Esempio n. 1
0
        public static OperatingSystemInfo ReadOperatingSystemInfo()
        {
            OperatingSystemInfo os = new OperatingSystemInfo();

            try
            {
                ManagementObjectSearcher    searcher = new ManagementObjectSearcher("SELECT TotalVisibleMemorySize, OSLanguage, Caption, Version, CSDVersion, OtherTypeDescription, OSArchitecture FROM Win32_OperatingSystem");
                Dictionary <string, string> data     = new Dictionary <string, string>();

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj["Caption"] != null)
                    {
                        os.Name = queryObj["Caption"].ToString();
                    }

                    if (queryObj["Version"] != null)
                    {
                        os.Version = queryObj["Version"].ToString();
                    }

                    if (queryObj["CSDVersion"] != null)
                    {
                        os.ServicePack = queryObj["CSDVersion"].ToString();
                    }

                    if (queryObj["OtherTypeDescription"] != null)
                    {
                        os.AdditionalInfo = queryObj["OtherTypeDescription"].ToString();
                    }

                    if (queryObj["OSArchitecture"] != null)
                    {
                        os.Architecture = queryObj["OSArchitecture"].ToString();
                    }

                    if (queryObj["TotalVisibleMemorySize"] != null)
                    {
                        os.VisibleMemory = Util.ConvertKilobytesToMegabytes(UInt64.Parse(queryObj["TotalVisibleMemorySize"].ToString()));
                    }

                    if (queryObj["OSLanguage"] != null)
                    {
                        os.Language = queryObj["OSLanguage"].ToString();
                    }

                    break;
                }
            }
            catch (Exception e)
            {
                os.Name = "Error getting Operating System info: " + e.Message;
            }
            finally
            { }

            return(os);
        }
Esempio n. 2
0
        public static OperatingSystemInfo ReadOperatingSystemInfo()
        {
            OperatingSystemInfo os = new OperatingSystemInfo();

            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT TotalVisibleMemorySize, OSLanguage, Caption, Version, CSDVersion, OtherTypeDescription, OSArchitecture FROM Win32_OperatingSystem");
                Dictionary<string, string> data = new Dictionary<string, string>();

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj["Caption"] != null)
                    {
                        os.Name = queryObj["Caption"].ToString();
                    }

                    if (queryObj["Version"] != null)
                    {
                        os.Version = queryObj["Version"].ToString();
                    }

                    if (queryObj["CSDVersion"] != null)
                    {
                        os.ServicePack = queryObj["CSDVersion"].ToString();
                    }

                    if (queryObj["OtherTypeDescription"] != null)
                    {
                        os.AdditionalInfo = queryObj["OtherTypeDescription"].ToString();
                    }

                    if (queryObj["OSArchitecture"] != null)
                    {
                        os.Architecture = queryObj["OSArchitecture"].ToString();
                    }

                    if (queryObj["TotalVisibleMemorySize"] != null)
                    {
                        os.VisibleMemory = Util.ConvertKilobytesToMegabytes(UInt64.Parse(queryObj["TotalVisibleMemorySize"].ToString()));
                    }

                    if (queryObj["OSLanguage"] != null)
                    {
                        os.Language = queryObj["OSLanguage"].ToString();
                    }

                    break;
                }
            }
            catch (Exception e)
            {
                os.Name = "Error getting Operating System info: " + e.Message;
            }
            finally
            { }

            return os;
        }