How to detect the bitness of an operating system

Article translations Article translations
Close Close
Article ID: 2060044 - View products that this article applies to.
Expand all | Collapse all

On This Page

INTRODUCTION

This article describes an All-In-One Code Framework sample that is available for download. This sample includes a step-by-step guide about how to write Visual Basic.NET, Visual C++.NET, Visual Basic.NET, or Visual C# code to programmatically determine whether the operating system of the current computer or of a remote computer is a 64-bit operating system.

Download information

To download this code sample, click the following link:

    


Technical overview

The samples introduce two solutions of detecting programmatically whether you are running on a 64-bit operating system or not.

Solution 1. Use the IsWow64Process function to check the bitness of the running system.

If the running process is a 64-bit process, the current operating system must be a 64-bit operating system.

#if defined(_WIN64)
return TRUE; // 64-bit programs run only on Win64

If the running process is a 32-bit process, you can use the IsWow64Process function to check whether the current operating system is a 64-bit operating system or not.

#elif defined(_WIN32)
// 32-bit programs run on both 32-bit and 64-bit Windows
BOOL f64bitOS = FALSE;
return ((DoesWin32MethodExist(L"kernel32.dll", "IsWow64Process") &&
IsWow64Process(GetCurrentProcess(), &f64bitOS)) && f64bitOS);


Solution 2. Use the AddressWidth property of the WMI class Win32_Processor to query the bitness of the local or any remote systems.

The AddressWidth property of the WMI class Win32_Processor dictates the current operating mode of the processor. On a 32-bit operating system, Win32_Processor.AddressWidth would be 32; on a 64-bit operating system, Win32_Processor.AddressWidth would be 64.

The OSArchitecture property of the WMI class Win32_OperatingSystem can also tell the bitness of OS, but the property is only available on Windows Vista and newer operating systems.


NoteFor more information about how to create the sample application and how to deploy the sample application, see the Readme.txt file that is included in the download package.

Technology category

  • Windows Base

Languages

This code sample contains the following programming languages:

Collapse this tableExpand this table
LanguageProject Name
Visual C++CppCheckOSBitness
Visual C#CSCheckOSBitness
Visual Basic.NETVBCheckOSBitness

Prerequisites

  • This sample application was created by using Microsoft Visual Studio 2008 with Service Pack 1 installed.


MORE INFORMATION

What is All-In-One Code Framework?

All-In-One Code Framework shows most Microsoft development techniques by using code samples in different programming languages. Each example is carefully selected, composed, and documented to show one common code scenario. For more information about All-In-One Code Framework, visit the following Web site:
http://1code.codeplex.com

How to find more All-In-One Code Framework samples

To find more All-In-One Code Framework samples, you can simply click the following link:
http://support.microsoft.com/gp/gp_kbcodefx

REFERENCES

How to detect programmatically whether you are running on 64-bit Windows
http://blogs.msdn.com/oldnewthing/archive/2005/02/01/364563.aspx


Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Properties

Article ID: 2060044 - Last Review: July 20, 2010 - Revision: 2.0
APPLIES TO
  • Microsoft Visual Studio 2008 Service Pack 1
Keywords: 
kbcodefx kbrapidpub kbnomt atdownload kbsurveynew kbinfo KB2060044

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com