Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to detect the platform of a running process by using VC++, VC#, and VB.NET


INTRODUCTION

This article describes an All-In-One Code Framework sample that is available for download. The code sample demonstrates the following platform detection tasks:

  • 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.

Difficulty level

Download information

To download this code sample, click the following link:

Technical overview

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:

General information about Win32_OperatingSystem class

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:

How to get the system version


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:

    General information about Environment.OSVersion Property

    Note For more information about the OperatingSystem class, please visit the following Microsoft website:

    General information about OperatingSystem class

    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:

    General information about Environment.Is64BitOperatingSystem property

Determine whether a process is a 64-bit process

If 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:

BOOL Is64BitProcess(void)
    {
    #if defined(_WIN64)
        return TRUE;   // 64-bit program
    #else
        return FALSE;
    #endif
    }
 



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:

General information about Environment.Is64BitProcess property


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.

Technology category

  • Windows Base

Languages

This code sample contains the following programming languages.

Language Project Name
Visual C++ .NET CppPlatformDetector
Visual C# CSPlatformDetector
Visual Basic .NET VBPlatformDetector

Prerequisites

  • This sample application is created by using Visual Studio 2010 and the .NET Framework 4.

↑ Back to the top


More Information

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 samples

To 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:

↑ Back to the top


References

For more information about how to detect programmatically whether you are running on 64-bit Windows, visit the following website:

↑ Back to the top


Rapid publishing disclaimer

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.

↑ Back to the top


Keywords: kbcodefx, kbinfo, kbnomt, kbsurveynew, atdownload, kbrapidpub, kb

↑ Back to the top

Article Info
Article ID : 2451461
Revision : 3
Created on : 4/23/2018
Published on : 4/23/2018
Exists online : False
Views : 185