Page 1 of 1

Find the "programm files" folder for both platform: 32/64bit

Posted: 26 Aug 2010 03:50
by budhax
Hello,
1. Is this script a good/safe way to find the folder where softwares are installed,
independently of the platform 32bit or 64bit ?

Code: Select all

SET PF=%PROGRAMFILES%
IF /i NOT "%PROCESSOR_ARCHITECTURE%"=="x86" SET PF=%PF% ^(x86^)
ECHO %PF%
Pause


2. On a MS Windows 64bit platform, where 64bit softwares are installed: in "Program files" or "Program files (x86)" folder ?

Thanks

Re: Find the "programm files" folder for both platform: 32/6

Posted: 26 Aug 2010 04:32
by orange_batch
It looks okay, but surrounding a whole assignment in quotations is safer because Command Prompt reads the characters as a string instead of literal/command characters.

Code: Select all

SET "PF=%PROGRAMFILES%"
IF /i NOT "%PROCESSOR_ARCHITECTURE%"=="x86" SET "PF=%PF% (x86)"
ECHO:%PF%
Pause


The one glaring problem I see with this, is if you are running Windows x86 on an x64 processor. The appended (x86) to Program Files would not apply. So make sure any x64 computers are running Windows x64.

However, you are much better off using the VER command line tool, since this is truly accurate.

Code: Select all

for /f "delims=[ tokens=1" %%x in ('ver') do if %%x=="Microsoft Windows XP x64 (or whatever is applicable)" ...