5404

How can I detect which version of Windows is running?

I have an application which runs as a Word add-in. (VSTO).

It runs on many PCs all over the world. In certain cases I need to trouble shoot problems (obviously remotely) and have a reporting mechanism which tells me which Windows OS is running - I use Environment.OSVersion in .NET. At least it did until Windows 10.

There is an article on MSDN (Targeting your application for Windows) about creating an application manifest which will enable the correct version to be returned.

But my application is a DLL, not an EXE and so won't really accommodate the XML code referred to in that article.

Is there no way to just ask Windows, "What version are you? Really, I won't cry if you admit to the real version".

Or an entry in the registry or something?

Answer1:

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 target manifest.

Answer2:

WMI is the best way to do this kind of stuff You can use this to retrieve OS informations :

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 fetch the OS details for you.

Answer3:

You can try GetVersionEx Win32 API.

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

Note that Windows 10 in fact is version 6.4. Ver 6.0 is Vista, 6.1 - 7, 6.2 - 8.

Recommend

  • datatables tabletools -> export only selected rows
  • Encrypt and Decrypt a string to fixed length
  • My cocos2d project stopped compiling! Over 40 errors! What to do? [closed]
  • ! [rejected] master -> master (fetch first)
  • SQL server 2008 domain change
  • ASP.NET redirect non existing pages to homepage in web.config using rewrite rules
  • package to fit mixtures of student-t distributions
  • ValidationNel Error after upgrading Scalaz to 7.2
  • Setting the width of a Silverlight combo box to accommodate its widest item
  • The item $//Drops may not be cloaked because it does not have a mapped parent. (type WorkingFolderEx
  • How can I test the validity of a ReferenceProperty in Appengine?
  • Working efficiently on remote projects in Visual Studio
  • Declaration of does not work with Ionic's ion-nav-view in IBM MobileFirst
  • Prolog Query - Trying to understand how this result happens
  • How does ActiveSupport do month sums?
  • Azure table store snapshot/backup capability
  • How to disable all widgets inside Panel or inside Composite?
  • Security issues with PHP's Readfile method
  • Web.config system.webserver errors
  • Breaking out column by groups in Pandas
  • How solve “Qt: Untested Windows version 10.0 detected!”
  • Time complexity of a program which involves multiple variables
  • Play WS (2.2.1): post/put large request
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Asynchronous UI Testing in Xcode With Swift
  • Is my CUDA kernel really runs on device or is being mistekenly executed by host in emulation?
  • SSO with signing and signature validation doesn't work
  • Deserializing XML into class C#
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • 0x202A in filename: Why?
  • Is there a mandatory requirement to switch app.yaml?
  • How to include full .NET prerequisite for Wix Burn installer
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • File not found error Google Drive API
  • How can I remove ASP.NET Designer.cs files?
  • costura.fody for a dll that references another dll
  • How to Embed XSL into XML
  • java string with new operator and a literal
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize