How to get Windows Version - as in “Windows 10, version 1607”?

后端 未结 4 1051
既然无缘
既然无缘 2020-12-14 07:41

It seems that the word \"version\" in reference to Windows is used for different things. For example, the Windows 10 \"Anniversary Update\" is labeled \"Version 1607\" by Mi

4条回答
  •  余生分开走
    2020-12-14 07:55

     private static ManagementObject GetMngObj(string className)
        {
            var wmi = new ManagementClass(className);
    
            foreach (var o in wmi.GetInstances())
            {
                var mo = (ManagementObject)o;
                if (mo != null) return mo;
            }
    
            return null;
        }
    
        public static string GetOsVer()
        {
            try
            {
                ManagementObject mo = GetMngObj("Win32_OperatingSystem");
    
                if (null == mo)
                    return string.Empty;
    
                return mo["Version"] as string;
            }
            catch (Exception e)
            {
                return string.Empty;
            }
        }
    

    How to Use:

    Console.WriteLine(GetOsVer());
    

    Result: 10.0.0.1299

提交回复
热议问题