/// <summary>
        /// Extract System Information in the UDFStructSysInfo
        /// </summary>
        public void ExtractSysInformation()
        {
            sysinfo=new UDFStructSysInfo();
            /*
             * get information from Win32_OperatingSystem
             *
             */

            // Get process info including a method to return the user who is running it
            System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("select Name,ServicePackMajorVersion,ServicePackMinorVersion,TotalVirtualMemorySize  from Win32_OperatingSystem");
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs,oQuery);
            ManagementObjectCollection oReturnCollection = oSearcher.Get();
            /*
            Name
            ServicePackMajorVersion
            ServicePackMinorVersion
            TotalVirtualMemorySize
            */
            foreach( ManagementObject oReturn in oReturnCollection )
            {
                if(oReturn["Name"]!=null)
                {
                    sysinfo.strOperatingSystem=oReturn["Name"].ToString();;
                }

                if(oReturn["ServicePackMajorVersion"]!=null)
                {
                    sysinfo.strOperatingSystemPack=oReturn["ServicePackMajorVersion"].ToString();
                }

                if(oReturn["ServicePackMinorVersion"]!=null)
                {
                    sysinfo.strOperatingSystemPack=sysinfo.strOperatingSystemPack+"." + oReturn["ServicePackMinorVersion"].ToString();
                }
                if(oReturn["TotalVirtualMemorySize"]!=null)
                {
                    /*
                     * Maximum number, in kilobytes, of memory that can be allocated to a process. For operating systems with no virtual memory, typically this value is equal to the total amount of physical memory minus the memory used by the BIOS and OS. For some operating systems, this value may be infinity, in which case 0 (zero) should be entered. In other cases, this value could be a constant, for example, 2G or 4G.
                     */
                    sysinfo.nTotalVirtualMemory=(Convert.ToInt64(oReturn["TotalVirtualMemorySize"].ToString()))/1024;
                }
            }

            oQuery = new System.Management.ObjectQuery("select *  from Win32_Processor");
            oSearcher = new ManagementObjectSearcher(oMs,oQuery);
            oReturnCollection = oSearcher.Get();
            /*
             * Descritption
             */
            foreach( ManagementObject oReturn in oReturnCollection )
            {
                if(oReturn["CurrentClockSpeed"]!=null)
                {
                    sysinfo.strProcessorName=oReturn["CurrentClockSpeed"].ToString();
                }
            }

            oQuery = new System.Management.ObjectQuery("select Manufacturer,TotalPhysicalMemory,Model  from Win32_ComputerSystem");
            oSearcher = new ManagementObjectSearcher(oMs,oQuery);
            oReturnCollection = oSearcher.Get();
            /*
             * Descritption
             */
            foreach( ManagementObject oReturn in oReturnCollection )
            {
                if(oReturn["Manufacturer"]!=null)
                {
                    sysinfo.strProcessorName=sysinfo.strProcessorName + "-" + oReturn["Manufacturer"].ToString();
                }
                if(oReturn["TotalPhysicalMemory"]!=null)
                {
                    /* Qualifiers: Units(Bytes)
                     * Total size of physical memory. Be aware that, under some circumstances, this property may not return an accurate value for the physical memory. For example, it is not accurate if the BIOS is using some of the physical memory.
                     * */
                    System.Int64  TotalRam=Convert.ToInt64(oReturn["TotalPhysicalMemory"].ToString());
                    sysinfo.nPhysicalRam=(int)((TotalRam/1024)/1024);
                }
                if(oReturn["Model"]!=null)
                {
                    sysinfo.strProcessorName=sysinfo.strProcessorName + "-" + oReturn["Model"].ToString();
                }
            }

            //			System.Environment.o
            //			foreach( ManagementObject oReturn in oReturnCollection )
            //			{
            //				oReturn[Name]
            //			}
        }
Beispiel #2
0
        /// <summary>
        /// Extract System Information in the UDFStructSysInfo
        /// </summary>
        public void ExtractSysInformation()
        {
            sysinfo = new UDFStructSysInfo();

            /*
             * get information from Win32_OperatingSystem
             *
             */

            // Get process info including a method to return the user who is running it
            System.Management.ObjectQuery oQuery            = new System.Management.ObjectQuery("select Name,ServicePackMajorVersion,ServicePackMinorVersion,TotalVirtualMemorySize  from Win32_OperatingSystem");
            ManagementObjectSearcher      oSearcher         = new ManagementObjectSearcher(oMs, oQuery);
            ManagementObjectCollection    oReturnCollection = oSearcher.Get();

            /*
             * Name
             * ServicePackMajorVersion
             * ServicePackMinorVersion
             * TotalVirtualMemorySize
             */
            foreach (ManagementObject oReturn in oReturnCollection)
            {
                if (oReturn["Name"] != null)
                {
                    sysinfo.strOperatingSystem = oReturn["Name"].ToString();;
                }

                if (oReturn["ServicePackMajorVersion"] != null)
                {
                    sysinfo.strOperatingSystemPack = oReturn["ServicePackMajorVersion"].ToString();
                }

                if (oReturn["ServicePackMinorVersion"] != null)
                {
                    sysinfo.strOperatingSystemPack = sysinfo.strOperatingSystemPack + "." + oReturn["ServicePackMinorVersion"].ToString();
                }
                if (oReturn["TotalVirtualMemorySize"] != null)
                {
                    /*
                     * Maximum number, in kilobytes, of memory that can be allocated to a process. For operating systems with no virtual memory, typically this value is equal to the total amount of physical memory minus the memory used by the BIOS and OS. For some operating systems, this value may be infinity, in which case 0 (zero) should be entered. In other cases, this value could be a constant, for example, 2G or 4G.
                     */
                    sysinfo.nTotalVirtualMemory = (Convert.ToInt64(oReturn["TotalVirtualMemorySize"].ToString())) / 1024;
                }
            }

            oQuery            = new System.Management.ObjectQuery("select *  from Win32_Processor");
            oSearcher         = new ManagementObjectSearcher(oMs, oQuery);
            oReturnCollection = oSearcher.Get();

            /*
             * Descritption
             */
            foreach (ManagementObject oReturn in oReturnCollection)
            {
                if (oReturn["CurrentClockSpeed"] != null)
                {
                    sysinfo.strProcessorName = oReturn["CurrentClockSpeed"].ToString();
                }
            }

            oQuery            = new System.Management.ObjectQuery("select Manufacturer,TotalPhysicalMemory,Model  from Win32_ComputerSystem");
            oSearcher         = new ManagementObjectSearcher(oMs, oQuery);
            oReturnCollection = oSearcher.Get();

            /*
             * Descritption
             */
            foreach (ManagementObject oReturn in oReturnCollection)
            {
                if (oReturn["Manufacturer"] != null)
                {
                    sysinfo.strProcessorName = sysinfo.strProcessorName + "-" + oReturn["Manufacturer"].ToString();
                }
                if (oReturn["TotalPhysicalMemory"] != null)
                {
                    /* Qualifiers: Units(Bytes)
                     * Total size of physical memory. Be aware that, under some circumstances, this property may not return an accurate value for the physical memory. For example, it is not accurate if the BIOS is using some of the physical memory.
                     * */
                    System.Int64 TotalRam = Convert.ToInt64(oReturn["TotalPhysicalMemory"].ToString());
                    sysinfo.nPhysicalRam = (int)((TotalRam / 1024) / 1024);
                }
                if (oReturn["Model"] != null)
                {
                    sysinfo.strProcessorName = sysinfo.strProcessorName + "-" + oReturn["Model"].ToString();
                }
            }



//			System.Environment.o
//			foreach( ManagementObject oReturn in oReturnCollection )
//			{
//				oReturn[Name]
//			}
        }