Dir .: C:\Program Files (x86) and c:\Program Files

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1777
Joined: 16 Oct 2013, 13:53

Dir .: C:\Program Files (x86) and c:\Program Files

Post by Albireo » 11 Feb 2015, 10:23

Hello!
In this computer I have two program catalogs.
One catalog is "c:\Program Files" and the other "c:\Program Files(x86)".
I have no idea what is different between these programs directories.

If I use the AHK system variable A_ProgramFiles, it contains c:\Program Files

I want to create an shortcut to an installed windows program.
That's no problem to use A_ProgramFiles if the win program is installed in "c:\Program Files\..."
But, if the AHK Application is moved from computer "1" with the win prog installed on "c:\program_files\..." to computer "2". The Win program is installed in "c:\program_files(x86)\..."
________

Is the only way is to change my AHK-script to the right program path on every computer?

//Jan

enthused
Posts: 94
Joined: 27 Dec 2014, 03:28

Re: Dir .: C:\Program Files (x86) and c:\Program Files

Post by enthused » 11 Feb 2015, 10:29

Albireo wrote:Hello!
In this computer I have two program catalogs.
One catalog is "c:\Program Files" and the other "c:\Program Files(x86)".
I have no idea what is different between these programs directories.
32 bit and 64 bit programs:
"c:\Program Files" has 64 bit programs.
"c:\Program Files(x86)" has 32 bit programs.

Figured I would clarify this part.

Elesar
Posts: 70
Joined: 31 Oct 2013, 07:56

Re: Dir .: C:\Program Files (x86) and c:\Program Files

Post by Elesar » 11 Feb 2015, 10:42

A simple if statement checking if the OS is 64bit or not will work.

Code: Select all

;Always have dir point to 32bit Program Files
if A_Is64bitOS
	dir := "C:\Program Files (x86)\Some Program"
else
	dir := "C:\Program Files\Some Program"

knix

Re: Dir .: C:\Program Files (x86) and c:\Program Files

Post by knix » 11 Feb 2015, 12:23

Elesar wrote:A simple if statement checking if the OS is 64bit or not will work.
Sometimes a user with 64bit Windows may have installed a 32bit version of some application though. So when writing ahk code that other people will use and that makes use of some installed program, check both locations

Code: Select all

if FileExist("C:\Program Files\golf\golf.exe") 
 dir := "C:\Program Files\golf\golf.exe"
else if FileExist("C:\Program Files (x86)\golf\golf.exe") 
 dir := "C:\Program Files (x86)\golf\golf.exe"
else
 return ;or whatever you want to do if golf.exe is not found
On second thought, I think some users may not have C: as drive for the Program Files folders. So a better version of the code would check that first. I guess (but can't test ATM) that the built in A_ProgramFiles variable can be parsed to detect the correct drive.

just me
Posts: 9560
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Dir .: C:\Program Files (x86) and c:\Program Files

Post by just me » 11 Feb 2015, 15:46

Code: Select all

#NoEnv
MsgBox, 0, ProgramFiles32, % ProgramFiles32()
ProgramFiles32() {
   If (A_Is64bitOS)
      EnvGet, PF32, ProgramFiles(x86)
   Else
      PF32 := A_ProgramFiles
   Return PF32
}

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Dir .: C:\Program Files (x86) and c:\Program Files

Post by boiler » 11 Feb 2015, 21:00

In some countries, the name of the directory isn't "Program Files" or "Program Files (x86)". It can use "Programme" or something like that. So it's best to use A_ProgramFiles or the environmental variables to get everything but the " (x86)" and then determine whether to add it or not once you determine which directory the file you want is in. Don't forget to include the space before "(x86)" or it won't find that directory.

knix

Re: Dir .: C:\Program Files (x86) and c:\Program Files

Post by knix » 12 Feb 2015, 04:55

Ok, so if we also cover that 64bit OS users may have 32bit version of a program installed we'd do:

Code: Select all

app := "\golf\golf.exe"
if FileExist(A_ProgramFiles app)
 dir := A_ProgramFiles app
else if FileExist(A_ProgramFiles " (x86)" app)
 dir := A_ProgramFiles " (x86)" app
else
 return ;or whatever you want to do if golf.exe is not found

Albireo
Posts: 1777
Joined: 16 Oct 2013, 13:53

Re: Dir .: C:\Program Files (x86) and c:\Program Files

Post by Albireo » 19 Feb 2015, 08:24

Thanks everyone!
The problem is not so easy to solve, but I think that the last solution can do it automaticly for me.
//Jan

Post Reply

Return to “Ask for Help (v1)”