Solved

Open a program??

Posted on 1998-01-27
18
793 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:stevenc317
  • 8
  • 5
  • 4
  • +1
18 Comments
 
LVL 2

Expert Comment

by:Llandr
ID: 1179281
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.

0
 
LVL 1

Author Comment

by:stevenc317
ID: 1179282
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.
0
 
LVL 7

Expert Comment

by:galkin
ID: 1179283
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)
0
 
LVL 1

Author Comment

by:stevenc317
ID: 1179284
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!!
0
 
LVL 7

Expert Comment

by:galkin
ID: 1179285
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.
0
 
LVL 2

Expert Comment

by:Llandr
ID: 1179286
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.
0
 
LVL 1

Author Comment

by:stevenc317
ID: 1179287
Llandr..

thanks!  But how do I get my app to look at that value and run it???
0
 
LVL 2

Expert Comment

by:Llandr
ID: 1179288
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.

0
 
LVL 7

Expert Comment

by:galkin
ID: 1179289
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:stevenc317
ID: 1179290
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????
0
 
LVL 7

Expert Comment

by:galkin
ID: 1179291
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.
0
 
LVL 2

Expert Comment

by:Llandr
ID: 1179292
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
0
 
LVL 1

Author Comment

by:stevenc317
ID: 1179293
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.

0
 
LVL 2

Expert Comment

by:Llandr
ID: 1179294
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>
0
 
LVL 1

Author Comment

by:stevenc317
ID: 1179295
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...
0
 
LVL 1

Author Comment

by:stevenc317
ID: 1179296
next person to send a blank answer will get the 15 points.  I want this off the server...
0
 
LVL 84

Accepted Solution

by:
ozo earned 10 total points
ID: 1179297
blank
0
 
LVL 1

Author Comment

by:stevenc317
ID: 1179298
thanks ozo
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now