Determine Program Files Directory

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Determine Program Files Directory

Post by kpassaur » Tue Mar 24, 2009 9:22 am

I have a program that I use to create installs for compiled MS Scripts and it works fine. In the past I have always used a fixed sub directory off of the C: drive. However I am now installing to a sub directory of "Program Files" and this is where the difficulty comes.

In different languages Program Files is called something different. For instance in Swedish it is called just "C:\Program". The installer knows where to place the files and does so correctly, but I don't know how to point to them to execute them.

Is there a way to determine the programs directory like there is the windows temp directory path (TEMP_DIR)?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Mar 24, 2009 11:22 am

GetEnvVar>ProgramFiles,Prog_Files
MessageModal>Prog_Files
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

GetEnvVar>

Post by kpassaur » Tue Mar 24, 2009 12:13 pm

Thanks,

As ususal when I find something new I look it up in the help file. So, I checked the help file for "GetEnvVar>" and it didn't say much. Is there a list of the items it can get?

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Mar 24, 2009 12:42 pm

Open a DOS prompt, type "set" and press enter. All the environment variables on that computer will be displayed.

You should also be aware that environment variables can be set by the user or by other programs. That's why they're called "variables". The point is there can be an issue if for example the "ProgramFiles" environment variable was reset to have a value of C:\windows. Its not likely to happen. But you should be aware that it could.

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Set

Post by kpassaur » Tue Mar 24, 2009 12:59 pm

JRL

Thanks, I have decided that the best way to go on this is to write the path to the progam in the registry and then read it so that it will make no difference where it is installed.

Naturally, the down side is that the install needs to be run before the progam is written. Not really a big deal as when writing it, the registry lines can be written and then remarked out before compile time.

kp

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Mar 24, 2009 1:47 pm

Another way:

Code: Select all

Let>PATH_SIZE=260
Let>CSIDL_PROGRAM_FILES=38

LibFunc>shell32.dll,SHGetFolderPathA,r,0,CSIDL_PROGRAM_FILES,0,0,PATH

Pos>NULLCHAR,r_5,1,p
MidStr>r_5,1,{%p%-1},ProgFiles

MessageModal>ProgFiles
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Tue Mar 24, 2009 4:21 pm

Hi Marcus,

Thanks for the above method of directly determining the Programs directory (without having to write to the registry) but can you also tell us why you used the following line?
  • Let>PATH_SIZE=260
According to the Help File, PATH_SIZE is not a Macro Scheduler system variable.

You don't reference that variable again in your script... so no other command is making use of it... so why are you setting it to 260?

I searched the forums and the only other mention of PATH_SIZE is in some similar code you posted here: list of file/path references?

Thanks
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Mar 24, 2009 4:32 pm

Please see the LibFunc help topic.

I use PATH as the buffer variable in the LibFunc call. Adding _SIZE to the variable placed in the LibFunc call is done to specify the size of the buffer.

The docs for SHGetFolderPathA say the buffer should be MAX_PATH which is 260.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Tue Mar 24, 2009 5:31 pm

Hi Marcus,

Very good, I see it now, thanks for the clarification.

All I could find about "MAX_PATH" from Microsoft was here: http://msdn.microsoft.com/en-us/library/aa365247.aspx

It says it is 260 chars.

What link were you using as documentation on the SHGetFolderPathA win32 api call?

I'm finding pages marked "depricated" as Vista must use a different call to achieve the same thing.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts