I was recently writing a batch script to auto-install service packs onto windows, detecting the OS version was relatively simple and there’s plenty of scripts on the internets to do this; on the otherhand, detecting between 32 and 64bit architectures is much more complicated.
Microsoft has a KB artictle with batch script code to do this which is great apart from it doesn’t work under a standard user account and might not even work on an admin account (it didn’t work on my domain admin account), so if MS can’t supply code that works is there even a detection method?
Some people suggest that you should be searching for the %programfiles(x86)% variable which is only on 64bit systems, this is great apart from it didn’t work either.
I then stumbled by chance on a great solution which is to check the %PROCESSOR_ARCHITECTURE% variable. This worked great! I have been told that if the machine has WMI disabled then this wouldn’t work but most systems have WMI enabled.
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" ( echo x64 "X:\Windows 7 x64 SP1.exe" /passive /norestart ) ELSE ( echo x86 "X:\Windows 7 x86 SP1.exe" /passive /norestart )
That’s the code that I’m now using to detect the architecture of the systema nd install the correct SP, although it will attempt to install the 32bit Service pack onto 64Itinium machines; an extra check can be included to test for that but I’m unlikely to stumble upon an Itinium based system in my 20 PC office…
Hope this is useful to others.