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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
budhax
Posts: 63
Joined: 09 Oct 2006 12:25

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

#1 Post by budhax » 26 Aug 2010 03:50

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

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

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

#2 Post by orange_batch » 26 Aug 2010 04:32

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)" ...

Post Reply