Run a Certain Command Line Based on x86 or x64 Architecture

I’ve published about running certain files based on the operating system type (see this posting about such VBScript code on my blog), but what if you want to run something based on processor type, i.e. x86 or x64?  The “problem” with VBScript is that it can be hell on earth dealing with command lines that involve quotes and switches.  How about a simple batch file instead?

@echo off

Set RegQry=HKLM\Hardware\Description\SystemCentralProcessor

REG.exe Query %RegQry% > checkOS.txt

Find /i "x86" < CheckOS.txt > StringCheck.txt

If %ERRORLEVEL% == 0 (
Echo "This is 32 Bit Operating system"
) ELSE (
Echo "This is 64 Bit Operating System"
)

Stolen from http://support.microsoft.com/kb/556009.  It’s beautiful, simple and gets the job done. You can just stick your command lines as they are between the ( )’s.  Here’s a sample of something I did for the push out of Creo Parametric 2.0:

@echo off

Set RegQry=HKLM\Hardware\Description\System\CentralProcessor

REG.exe Query %RegQry% > checkOS.txt

Find /i "x86" < CheckOS.txt > StringCheck.txt

If %ERRORLEVEL% == 0 (
"C:\creo 2.0\Common Files\M040\install\addon\creoagent_32.msi" /passive
) ELSE (
"C:\creo 2.0\Common Files\M040\install\addon\creoagent_32_64.msi" /passive
)

Of course, it would be much simpler to dump Windows XP and every 32-bit operating system known to man.  If you have multiple lines, you will probably want to use something like start /w to wait for each line to finish, otherwise it will run every line all in one go.

– Soli Deo Gloria

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.