- Detect the name of the current operating system. For example, detect that you are running Microsoft Windows 7 Enterprise.
- Detect the version of the current operating system. For example, detect that you are running Microsoft Windows NT 6.1.7600.0.
- Determine whether the current operating system is a 64-bit operating system.
- Determine whether the current process is a 64-bit process.
- Determine whether an arbitrary process running on the system is 64-bit.
Download informationTo download this code sample, click the following link:
Detect the name of the current operating system
The name of the operating system can be detected from the Caption property of the Win32_Operating System WMI class.
Note For more information about the Win32_Operating System WMI class, please visit the following Microsoft website: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
- 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: Note For more information about the OperatingSystem class, please visit the following Microsoft website:
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:
Determine whether a process is a 64-bit processIf you want to determine whether a running process is a 64-bit process, you can run the following code to determine the Boolean type return value by using the VC++ preprocessor symbols:
return TRUE; // 64-bit program
You can also use the Environment.Is64BitProcess property in the .NET Framework 4 if you are running C# or VB.NET code.
Note For more information about the Environment.Is64BitProcess 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.
- Windows Base
LanguagesThis code sample contains the following programming languages.
|Visual C++ .NET||CppPlatformDetector|
|Visual Basic .NET||VBPlatformDetector|
- 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:
How to find more All-In-One Code Framework samplesTo find more All-In-One Code Framework samples, search for "kbcodefx" together with related keywords on the Microsoft support Web site. Or, visit the following Microsoft Web site:
Rapid publishing disclaimerMicrosoft 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.
Article ID: 2451461 - Last Review: Nov 17, 2010 - Revision: 1