Link to home
Start Free TrialLog in
Avatar of stevenc317
stevenc317

asked on

Open a program??

Hi I want to be able to run a program a from within my C++ application, I plan to use the following codes...

ShellExecute(NULL, "open", "FILE_NAME.exe",NULL, NULL, SW_SHOWNORMAL);

but I noticed that not everyone will have the FILE_NAME.exe in the folder that I think that have it in.  How do I setup some way of saving the path to the file in a RegEdit value?? Then use the RegEdit value to run the program. Do you understand???  Also in case you need to know I will using Borland C++ Builder.
Avatar of Llandr
Llandr

My initial response is to strip the application path from them argv[0] argument in the argument line. this way you have the application path and i suppose you can append this to the FILE_NAME.

Avatar of stevenc317

ASKER

I don't think you understand me.. Here let me try again.

I want to be able to run Netscape Communicator from within my program.  But not everyone will install Netscape in the default directory (C:\Program Files\Netscape\Communicator\Program\netscape.exe).  How can I ask the user to locate the file (that part I can do) and save the path (and exe file name) to a registory value, that way whenever the user wants to load the program the info is right there in the reg for my app to run it.
If you want to open file of specified type first use FindExecutable to locate executable associated with this file type and then call ShellExecute. If you want to launch specific executable( i.e. netscape.exe) you must perform global or restricted search with FindFirstFile(Ex)
ok, but how do I save the path to a registory value?  The user is not going to want to keep typing the path to the app every time he/she wants to run it!!
FindNextFile(Ex) used to locate executable takes as the second parameter reference WIN32_FIND_DATA, which if function succeded in locating file on return contains all file attributes including path to file.
If you look in the registry you find that the value in
HKEY_USER\.Default\Software\Netscape\Netscape navigator\Main
contains a key named Install Directory. It should be sufficient to find the executable.
Llandr..

thanks!  But how do I get my app to look at that value and run it???
You hav to use the Registry API to access this.
First open the key using RegOpenKeyEx then get the value using RegQueryValueEx.
You can find the documentation of RegOpenKeyEx and RegQueryValueEx in the help-files.

When you use ShellExecute this function locates executable either by full path you provide or if you specify only file name it looks into registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths. This key has subkeys, each subley is file name and its default value is full path to this file. Most program create their subkey during installation so you don't need to specify path to lauch them either using ShellExecute or from Windows Run dialog. If your application doesn't do this you can once locate it with FindExecutable and then create subkey in registry. Next time you( and anyone else) can launch this executable without providing executable path but only file name with extension.
By the way I sure nescape has already such a key so you can launch it without providing path.
thanks, I will do that.  But I still need to know how to save information into the reg and view info.  I just finished a Options section, when enters data in to text blank and clicks on the Update button I want the infor to be saved in a reg key, how????
I don't understand what you want to save. I told you if application has already created key under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths and specified there its full path you don't need any path just provide file name with exetension to pass to ShellExecute. If application doesn't create this subkey or you have move executable to another folder, so shellExecute fails you can use FindExecutable to locate it and create necessary register key yourself or change default value of existing key to correct path so next time you will not need to provide path.
Just a comment. ShellExecute doesn't allow you to access Netscape Navigator, it allows you to access the extension associated with ".htm" (example) if you have several browsers it will not automatically find netsacep, just the one assoicated with ".htm".
If you wanät to save your data look at the other Reg-functions
Ok, I understand that Netscape has a key and I can just use that key to run the program.  What I am talking about now, is how do I save information into the registory??  For example username, version # of software, etc.

Use the save use RegOpenKeyEx or RegCreateKeyEx to find/create the entry and then use RegSetValueEx to create your own value.
I suggest that you use the path:
HKEY_USER\.Default\Software\<Your program here>
thanks, but could you make me a little snipplet of codes??  I want it to take whatever is in Edit1 and put it in HKEY_USER\.Default\Software\Voltage Software\webmaster\user name

Can you do that???  If you do I will give u the 15 points...
next person to send a blank answer will get the 15 points.  I want this off the server...
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks ozo