How to: Retrieve the Windows Version (C++/CLI)


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at How to: Retrieve the Windows Version (C++/CLI).

The following code example demonstrates how to retrieve the platform and version information of the current operating system. This information is stored in the Environment.OSVersion property and consists of an enumeration that describes the version of Windows in broad terms and a Version object that contains the exact build of the operating system.

// os_ver.cpp  
// compile with: /clr  
using namespace System;  
int main()   
   OperatingSystem^ osv = Environment::OSVersion;  
   PlatformID id = osv->Platform;  
   Console::Write("Operating system: ");  
   if (id == PlatformID::Win32NT)  
   else if (id == PlatformID::Win32S)  
   else if (id == PlatformID::Win32Windows)  
   Version^ version = osv->Version;  
   if (version)  
      int build = version->Build;  
      int major = version->Major;  
      int minor = version->Minor;  
      int revision = Environment::Version->Revision;  
      Console::Write("OS Version: ");  
                   build, major, minor, revision);  
   return 0;  

Windows Operations (C++/CLI)
.NET Programming with C++/CLI (Visual C++)