Program Locations

Discussions about CSEntry
Post Reply
Guest

Program Locations

Post by Guest »

In the menu system that we use, we usually have the directory name of where CSPro is stored hard coded into the application, e.g.

CSPro = "C:\Program Files\CSPro 4.0"; { CSPro directory }

With Windows 7 the directory is often “Program Files (x86)”, and if you have data entry set up with a mix of Windows 7 and earlier machines then you need two different set ups. I can program around this with FileExists to see where CSPro is stored, but I wondered if there is a simpler way of getting the path for a particular executable.

While CSPro would be the priority, I also launch Word and Excel from my CSPro menu from time to time, so something that would work for those too would be useful. If there is no simple solution, I will just go back to my method using FileExists.
Gregory Martin
Posts: 1791
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Program Locations

Post by Gregory Martin »

If launching CSPro applications, the new version of CSPro, 4.1, has a feature called execpff. It eliminates the need to know the directory where the CSPro files are located. This is important for two reasons. One is the reason that you mentioned, which is a difference between 32- and 64- bit machines. On 64-bit machines, 32-bit programs, such as CSPro, are stored in a folder with the name "Program Files (x86)." But another reason is that hard coding "CSPro 4.0," for instance, means that you might potentially have to make a lot of changes to code when a new version of CSPro comes out. So whenever possible, using execpff is ideal:
execpff("launcher.pff");
However, for programs like Word or Excel, or any other program located in the Program Files folder, you will have to use the trick that you mention. Making a function might be the most useful:
alpha (300) tempString;
function alpha (300) qualifyProgramFilesApplication(alpha (100) applicationName)

    
// first test on a 32-bit machine
    tempString = maketext("C:\\Program Files\\%s",applicationName);
    
    
if not fileexist(tempString) then
        
// must be a 64-bit machine, or the application name was invalid
        tempString = maketext("C:\\Program Files (x86)\\%s",applicationName);
    
endif;
    
    qualifyProgramFilesApplication = tempString;

end;

PROC EXAMPLE

preproc

    
execsystem(qualifyProgramFilesApplication("CSPro 4.1\\CSFreq.exe"));
    
execsystem(qualifyProgramFilesApplication("Microsoft Office\Office12\excel.exe"));


Last bumped by Anonymous on July 1st, 2012, 2:23 pm.
Post Reply