How to determine which version of Windows is running?

I have an application that works as a Word add-in. (ESPO).

It works on many PCs around the world. In some cases, I have to worry about shooting issues (obviously remotely) and have a reporting mechanism that tells me which Windows OS it works with - I use it Environment.OSVersionin .NET. At least until Windows 10.

There is an article on MSDN ( Targeting Your Windows Application ) about creating an application manifest that will return the correct version.

But my application is a DLL, not an EXE, so the XML code mentioned in this article will not actually be hosted.

Is there a way to just ask Windows: “Which version? Indeed, I will not cry if you agree to the current version.”

Or a registry entry or something else?

+2
source share
3 answers
private String GetOSVersion()
{
    var wmiEnum = new ManagementObjectSearcher("root\\CIMV2", "SELECT Version FROM  Win32_OperatingSystem").Get().GetEnumerator();
    wmiEnum.MoveNext();
    return wmiEnum.Current.Properties["Version"].Value as String;
}

Returns 6.1.7601 on my W7 system and 10.0.14393 on my Server 2016 system.

No need to add a goal manifest.

0
source

WMI is the best way to make this stuff. You can use it to get information about the OS:

ManagementObjectSearcher objMOS = 
       new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM  Win32_OperatingSystem");

OS.Name = ((string)objMOS["Caption"]).Trim();
OS.Version = (string)objMOS["Version"];
OS.MaxProcessCount = (uint)objMOS["MaxNumberOfProcesses"];
OS.MaxProcessRAM = (ulong)objMOS["MaxProcessMemorySize"];
OS.Architecture = (string)objMOS["OSArchitecture"];
OS.SerialNumber = (string)objMOS["SerialNumber"];
OS.Build = ((string)objMOS["BuildNumber"]).ToUint();

This can get OS information for you.

-1
source

You can try the GetVersionExWin32 API.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx

Please note that Windows 10 is actually version 6.4. Version 6.0 - Vista, 6.1 - 7, 6.2 - 8.

-1
source

Source: https://habr.com/ru/post/1598974/


All Articles