Can I check to see if current machine is running 64bit OS or 32bit OS inside a batch file?
EDIT:
Found this online and it is good enough to me now:
Can I check to see if current machine is running 64bit OS or 32bit OS inside a batch file?
EDIT:
Found this online and it is good enough to me now:
FYI, try and move away from using %PROCESSOR_ARCHITECTURE% as SCCM made a change around version 2012 which always launces Packages/Programs under a 32-bit process (it can install x64 but environment variables will appear as x86). I now use;
IF EXIST "%SystemDrive%\Program Files (x86)" GOTO X64
Jack
Will appear on Win32, and
will appear for Win64.
If you are perversely running the 32-bit
cmd.exe
process then Windows presents two environment variables:You can use the following registry location to check if computer is running 32 or 64 bit of Windows operating system:
You will see the following registry entries in the right pane:
The above
x86
and0x00000020(32)
indicate that the operating system version is 32 bit.After much trial and error, I managed to get a few different working examples, but the kicker was when the batch was launched on a 64bit OS on a 32bit CMD. In the end this was the simplest check I could get to work, which works on Win2k-Win8 32/64. Also big thanks to Phil who helped me with this.
Many DOS commands in the different versions of Windows are similar but may support different parameters. Plus, newer versions of Windows may support new commands or retire older ones. Thus, if you wish to write a batch file that can run on different types of machines, it may prove beneficial to determine the version of Windows on which the batch file is running. This way the batch file can execute commands appropriate to the operating system.
The following batch file will determine whether or not the machine is running Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000, or Windows NT. It can easily be modified to support other versions of Windows as necessary or to set an environment variable based on the version of Windows detected. Note that for this batch file to correctly discern between newer versions of Windows Server and consumer versions of Windows, it is more convoluted than batch files you may see elsewhere. I have explained the reasoning below.
1) Open a Notepad window.
2) Copy the following text into Notepad (you may want to access this tip's printed version as some lines wrap):
3) Save the file as %WINDIR%\whichvers.bat
4) Now, from the command prompt, enter:
whichvers
This will display which version of Windows you are running.
NOTES:
The reasoning for using the SYSTEMINFO command rather than relying on the VER command is because Windows Server 2008 "shares" version numbers with other Windows releases (see Microsoft). Thus relying on a "version number" of 6.0 to detect Windows Vista or 6.1 to detect Windows 7 fails to differentiate a machine from Windows Server 2008 or Windows Server 2008 R2.
The creation of %TEMP%\osname.txt is solely because I could not place the results of systeminfo | find "OS Name" directly into the for /f command - it does not like piped commands. You may find an easier way to handle grabbing the information from SYSTEMINFO - if so, please comment.
The environment variable %vers% has leading spaces. I could remove these with a longer batch file, but in this case it is not necessary.
The batch file detects for SYSTEMINFO as it assumes if it gets beyond the older operating system detections, the running version of Windows is even older and will not have this utility. On Windows 7 64-bit it is still located in the %SystemRoot%\system32 folder - if later versions of Windows become 64-bit only, this batch file may have to be updated.
Return to the Windows XP and DOS page.