You can find the C++, C#, and VB.NET code that queries the value of Win32_OperatingSystem.Captionproperty in the GetOSName function of the code sample.Alternatively, you can build the string of the operating system name by using the GetVersionEx, GetSystemMetrics, GetProductInfo, and GetNativeSystemInfo functions.
Note For more information about how to build the string of the operating system name by using the GetVersionEx, GetSystemMetrics, GetProductInfo, and GetNativeSystemInfo functions, visit the following Microsoft website:
Note This solution may not apply to versions of Windows later than Windows 7.
Detect the version of the current operating system
For C++ code, the OSVERSIONINFOEX structure that is outputted by the GetVersionEx function contains the following information:
The dwMajorVersion major version number
The dwMinorVersion minor version number
The dwBuildNumber build number
The wServicePackMajor major version number of the latest Service Pack
The ServicePackMinor minor version number of the latest Service Pack
You can use these numbers to quick determine what the operating system is, whether a certain Service Pack is installed. Additionally, the OSVERSIONINFOEX.wProductType method can detect whether the operating system is a workstation, a server, or a domain controller.
For C# and VB.NET code, the System.Environment.OSVersion property returns an OperatingSystem object that contains the current platform identifier and version numbers.
Note For more information about the System.Environment.OSVersion property, please visit the following Microsoft website:
You can use these numbers to quick determine the current operating system and whether a certain Service Pack is installed.
Determine whether the operating system is a 64-bit operating system
For C++ code, if a running process is a 64-bit process, the operating system must be a 64-bit operating system. To programmatically detect whether a 32-bit program is running on 64-bit operating system, you can use the IsWow64Process function.
For C# and VB.NET code, the Environment.Is64BitOperatingSystem property in the .NET Framework 4 determines whether the current operating system is a 64-bit operating system.
Note For more information about the Environment.Is64BitOperatingSystem property, visit the following Microsoft website:
If you want to detect whether an arbitrary application is a 64-bit process, you need to detect whether the OS bit is 64-bit. To do this, use the IsWow64Process() method along with the target process handle.
This code sample contains the following programming languages.
Visual C++ .NET
Visual Basic .NET
This sample application is created by using Visual Studio 2010 and the .NET Framework 4.
What is All-In-One Code Framework?
All-In-One Code Framework uses code samples in different programming languages to illustrate most Microsoft development techniques. Each code sample is carefully selected, composed, and documented to show common code scenarios. For more information about All-In-One Code Framework, visit the following All-In-One Code Framework Web site:
Microsoft corporation and/or its respective suppliers make no representations about the suitability, reliability, or accuracy of the information and related graphics contained herein. All such information and related graphics are provided "as is" without warranty of any kind. Microsoft and/or its respective suppliers hereby disclaim all warranties and conditions with regard to this information and related graphics, including all implied warranties and conditions of merchantability, fitness for a particular purpose, workmanlike effort, title and non-infringement. You specifically agree that in no event shall Microsoft and/or its suppliers be liable for any direct, indirect, punitive, incidental, special, consequential damages or any damages whatsoever including, without limitation, damages for loss of use, data or profits, arising out of or in any way connected with the use of or inability to use the information and related graphics contained herein, whether based on contract, tort, negligence, strict liability or otherwise, even if Microsoft or any of its suppliers has been advised of the possibility of damages.