- How-to: Detecting 64 bit vs 32 bit
- Detect 64 bit processor hardware
- Detect a 64 bit Operating System
- Detect a 64 bit Process
- System Folders
- File location environment variables
- Run a 32 bit program
- Run a 64 bit program from a 32 bit process
- Exe 64bit Detector
- Review
- Free Download
- specifications
- Easily determine if an application has 32 or 64-bit architecture with this useful command-line based utility that offers straightforward handling
- What’s new in Exe 64bit Detector 2.1:
- Command-line based interface that provides users with a straightforward handling
- Quickly determine if an application has 32 or 64-bit architecture, with this lightweight utility
- Useful piece of software that will enable users to determine if their executables have a 32 or 64-bit architecture
- Detect 32-bit or 64-bit of Windows
- 13 Answers 13
- Detect 64bit OS (windows) in Python
- 21 Answers 21
How-to: Detecting 64 bit vs 32 bit
Before starting to look at this, its important to be clear about what you mean by «64 bit».
You can have a 64 bit CPU, a 64 bit operating system and a 64 bit process running.
Here are the possible combinations:
CPU Hardware | Operating System | Process | |
---|---|---|---|
32 bit hardware | 32 | 32 | 32 |
32 bit OS | 64 | 32 | 32 |
32 bit application | 64 | 64 | 32 (WOW) |
Full 64 bit | 64 | 64 | 64 |
Detect 64 bit processor hardware
There are a number of promising looking options in WMI and Systeminfo, but they all pertain to the OS not the CPU.
Obviously a 64 bit OS must be running 64 bit hardware, but a 32 bit OS could also be running on 64 bit hardware.
There is currently no known way of detecting this.
Detect a 64 bit Operating System
In Vista and greater, you can use WMIC OS get osarchitecture , or in WMI/CIM Win32_ComputerSystem/OSArchitecture
:: Installed OS
Set _os_bitness=64
IF %PROCESSOR_ARCHITECTURE% == x86 (
IF NOT DEFINED PROCESSOR_ARCHITEW6432 Set _os_bitness=32
)
Echo Operating System is %_os_bitness% bit
Via David Wang’s blog post: Detect OS Bitness
Windows 10 on ARM includes an x86-on-ARM64 emulation, so the possible values for PROCESSOR_ARCHITECTURE are: AMD64 or IA64 or ARM64 or (for 32 bit) x86
In PowerShell (3.0+) we can use:
Detect a 64 bit Process
We can detect this with the PROCESSOR_ARCHITEW6432 variable, AMD64 = a 32 bit process under WOW64 mode:
If «%PROCESSOR_ARCHITEW6432%» == «AMD64» ECHO 32 bit process
If not exist %SystemRoot%\SysNative\cscript.exe Echo 32 bit process
You may often see incorrect suggestions that testing for the existence of files in \windows\SysWOW64 or \windows\System32 can be used to detect 32 bit or 64 bit, but this will not work — the redirector will make both locations appear present to 32 bit and 64 bit processes.
In PowerShell (1.0+):
if ($env:PROCESSOR_ARCHITEW6432 -eq «AMD64»)
In PowerShell (3.0+) we can use:
System Folders
64 bit versions of Windows have dynamic system folders C:\Windows\sys* to support both 64 and 32 bit programs.
PowerShell.exe, CMD.exe and many other programs are available as both 32 bit or 64 bit.
The dynamic sys folders will appear differently to a 32 bit session and a 64 bit session:
32 bit folder | 64 bit folder | |
---|---|---|
32 bit session | C:\Windows\system32\ | C:\Windows\sysNative\ |
64 bit session | C:\Windows\sysWOW64\ | C:\Windows\system32\ |
By default a 32 bit session will launch 32bit executables from C:\Windows\System32\ but, if the OS is 64 bit, then you can still choose to launch 64 bit executables by specifying SysNative . A 32 bit session can also access 32 bit files by directly referencing the sysWOW64 folder.
By default a 64 bit session will launch 64bit executables also from C:\Windows\System32\ but you can still choose to launch 32 bit executables by specifying sysWOW64 .
The sysNative alias is not visible to 64 bit processes or programs and so cannot been seen in Windows Explorer.
The PROCESSOR_ARCHITEW6432 environment variable. If it’s set, then you’re in a 32-bit process on 64-bit Windows, and can use SysNative . If it’s not set, then you’re either in a 32-bit process on 32-bit Windows, or in a 64-bit process on 64-bit Windows. In that case, you can use System32 .
File location environment variables
Run a 32 bit program
To run a 32 bit program or utility on a 64 bit OS, the 32 bit executable file must be called from %SystemRoot%\SysWOW64\
So for example to run a VBScript as a 32 bit process, use:
Running %SystemRoot%\SysWOW64\cmd.exe will launch a 32 bit instance of CMD.exe even if the OS is 64 bit.
When you run a 32 bit shell (such as C:\windows\syswow64\cmd.exe ) and then try to launch a command from that shell, it will always look for a 32 bit version of the command, even if you explicitly use a full path to system32 , Windows will redirect to the 32 bit equivalent in syswow64 (if no 32 bit version of the command is found, then the new process will fail to launch.)
So the following will also run a 32 bit VBScript:
C:\windows\syswow64\cmd.exe
cscript.exe C:\scripts\demo.vbs
Run a 64 bit program from a 32 bit process
To run a 64 bit program from a 32 bit process use the virtual folder C:\Windows\sysnative
In many cases this is not needed as most utilities (e.g. ping.exe) have both a 32 bit and 64 bit version, however a few utilities (nbtstat, bcdedit) are only available as a 64-bit executable.
By default, running CMD from the start menu will launch a 64 bit process ( C:\Windows\System32\cmd.exe )
“It’s not so much that we’re afraid of change or so in love with the old ways, but it’s that place in between that we fear. it’s like being between trapezes”
Environment Variables — Documented (standard) and undocumented environment variables.
WMIC OS Get OSArchitecture
Q556009 — How to check if a computer is running a 32 bit or 64 bit Operating System. Expired content from 2018.
Q896458 — 64-bit Windows does not support 16-bit applications.
Exe 64bit Detector
Review
Free Download
specifications
Easily determine if an application has 32 or 64-bit architecture with this useful command-line based utility that offers straightforward handling
What’s new in Exe 64bit Detector 2.1:
- Fixed ‘access denied’ bug on Windows XP.
Read the full changelog
Users who handle numerous applications might, at some point, need to determine if an executable is running on 32 or 64-bit architecture. In most cases, this can be achieved manually, by opening the preferred application into a basic text editor and examining the code manually. Thankfully, there is a much quicker solution to such issues and it’s called Exe 64bit Detector. It will allow users to easily determine if an app is running on 32 or 64-bit architecture, by using the command-line editor.
Command-line based interface that provides users with a straightforward handling
Featuring no installation process or extra configuration, the utility can be easily initiated by opening a command-line editor instance and entering its name. Its functionality is quite straightforward, allowing even novice users to get around to it.
All they need to do is to indicate the file path of the executable that needs to be analyzed and use the syntax presented in the on-screen help menu. Furthermore, if one wishes to determine if an app has 32 or 64-bit architecture much faster, Exe 64bit Detector can be moved in the app’s directory and then the file path doesn’t need to be inputted anymore.
Quickly determine if an application has 32 or 64-bit architecture, with this lightweight utility
Being based on the command-line editor, means that Exe 64bit Detector is quite lightweight on resources and doesn’t require any special criteria for it to run. In addition to information about the file type (32 / 64-bit), the utility offers details about the status of ASLR, DEP or SEH parameters, for the analyzed applications.
Looking on the downside of things, Exe 64bit Detector doesn’t have too many shortcomings and one potential improvement would be to allow users even faster executable analysis. To this end, drag-and-drop capabilities would significantly increase its handling efficiency.
Useful piece of software that will enable users to determine if their executables have a 32 or 64-bit architecture
For those who require a compact and efficient utility for detecting if executables have 32 or 64-bit architecture, this utility could be a good choice. It will offer users a command-line based interface that will offer prompt response and little to no resource consumption. Featuring easy-to-use commands and an intuitive handling, Exe 64bit Detector will be accessible to novice and expericend users alike.
Detect 32-bit or 64-bit of Windows
I want to detect whether the current Windows OS is 32-bit or 64-bit. How to achieve it using C++? I don’t want processor type I want OS’s bit type. This is because you can install 32-bit OS on 64-bit processor.
13 Answers 13
The function to call is IsWow64Process or IsWow64Process2 . It tells your 32-bit application if it is running on a 64 bit Windows.
If the program is compiled for 64 bits, it will already know.
If your code is 64-bit and running, then Windows is 64-bit — nothing to check. If your process is 32-bit call IsWow64Process() — 32-bit processes run in WOW64 on 64-bit Windows and without WOW64 otherwise.
you can use IsWow64Process if your app is a 32 bit app, if it’s true you are running on an x64 OS, else it’s 32bit
You need to use GetNativeSystemInfo . Given that you expect this to work on a 32-bit operating system, you need to use LoadLibrary + GetProcAddress so that you can deal with this function not being available. So if that fails, you know it is a 32-bit operating system. If not, SYSTEM_INFO.wProcessorArchitecture gives you the real processor type instead of the emulated one.
Use GetNativeSystemInfo function. It gets a LPSYSTEM_INFO parameter to get what you want.
wProcessorArchitecture
The processor architecture of the installed operating system.
Here is another way: GetSystemWow64Directory — «Retrieves the path of the system directory used by WOW64. This directory is not present on 32-bit Windows.» and «On 32-bit Windows, the function always fails, and the extended error is set to ERROR_CALL_NOT_IMPLEMENTED .»
I personally am not sure about the usage of IsWow64Process since in MSDN in the description of the IsWow64Process there is the text «Note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows because the Kernel32.dll in current versions of 32-bit Windows also contains this function.»
You can run the windows command systeminfo as a process in your program.
One of the returning categories is System Type.
Its output reads: System Type: x86-based PC , or System Type: x64-based PC
This may be a more complicated solution than the one provided by others but I thought I would add it as a possibility. (Maybe you are after additional info as well.)
Answer for Newer Versions of Windows
While several people, and the Microsoft Docs, have suggested IsWow64Process2 for this, I have not seen any code examples in my research. That is why I wanted to contribute this answer to the community.
According to the running 32 bit applications documentation page, Microsoft recommends using the IsWow64Process2 for Windows 10 instead of IsWow64Process:
A 32-bit application can detect whether it is running under WOW64 by calling the IsWow64Process function (use IsWow64Process2 if targeting Windows 10).
This function works on Windows 10 version 1511 (client) and Windows Server 2016 and above.
This has two parameters via which information is returned: pProcessMachine and pNativeMachine. Both return Image File Machine Constants
pProcessMachine returns information about whether the target process is running under the WOW64 emulator or not, and if it is, what kind of process it is.
pNativeMachine returns information about the architecture of the Windows host.
Using both of these return values, one can determine if Windows is 32 bit or 64 bit (which is what the OP asked), and whether the process is running under WOW64 as well as whether the process is 32 or 64 bit.
Here is a function I wrote for these purposes:
Here is an example usage of the above function:
I could only test two scenarios of the above code because I only have 64 bit Windows on a 64 bit machine. I do not have a 32 bit machine nor 32 bit Windows, nor do I have any ARM machines. If someone can test other scenarios, I would appreciate some feedback about whether the design I have done works for them.
I wrote an article that goes into greater depth explaining how the above code works.
Detect 64bit OS (windows) in Python
Does anyone know how I would go about detected what bit version Windows is under Python. I need to know this as a way of using the right folder for Program Files.
21 Answers 21
platform module — Access to underlying platform’s identifying data
On 64-bit Windows, 32-bit Python returns:
And that means that this answer, even though it has been accepted, is incorrect. Please see some of the answers below for options that may work for different situations.
I think the best solution to the problem has been posted by Mark Ribau.
The best answer to the question for Python 2.7 and newer is:
On windows the cross-platform-function platform.machine() internally uses the environmental variables used in Matthew Scoutens answer.
I found the following values:
- WinXP-32: x86
- Vista-32: x86
- Win7-64: AMD64
- Debian-32: i686
- Debian-64: x86_64
For Python 2.6 and older:
To find the Python interpreter bit version I use:
I guess you should look in os.environ[‘PROGRAMFILES’] for the program files folder.
Came here searching for properly detecting if running on 64bit windows, compiling all the above into something more concise.
Below you will find a function to test if running on 64bit windows, a function to get the 32bit Program Files folder, and a function to get the 64bit Program Files folder; all regardless of running 32bit or 64bit python. When running 32bit python, most things report as if 32bit when running on 64bit, even os.environ[‘PROGRAMFILES’] .
Note: Yes, this is a bit hackish. All other methods that «should just work», do not work when running 32bit Python on 64bit Windows (at least for the various 2.x and 3.x versions I have tried).
Edits:
2011-09-07 — Added a note about why only this hackish method works properly.