[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help!

Posted on 1998-02-17
17
Medium Priority
?
258 Views
Last Modified: 2010-08-05
I am currently using the ShellExecute command to run applications from within my application.  Like this...

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

Well I need to tell my program where the other program (which is being launched form my app) is located.  I have been thinking and feal that using a reg key (which will be filed out when my setup application runs) tell it the directory that the file will be in.  How would I do that??  The reg key that will be used is...
HKEY_CURRENT_USER\High Voltage R&D\webmaster\install_dir

thanks
0
Comment
Question by:4099aol
  • 8
  • 8
17 Comments
 
LVL 3

Accepted Solution

by:
q2guo earned 80 total points
ID: 1182430
What you should do is create a text file with extension .reg containing the two lines below

REGEDIT4
HKEY_CURRENT_USER\High Voltage R&D\webmaster\install_dir

and inside you program call 'regedit file.reg'

0
 
LVL 32

Expert Comment

by:jhance
ID: 1182431
I'd suggest that you use the RegCreateKeyEx and RegQueryValueEx() API functions instead.
0
 

Author Comment

by:4099aol
ID: 1182432
do not understand your answer and do not uderstand your comment.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:q2guo
ID: 1182433
Ok, you can either do what I suggested.  Or go with jhance.

Call RegCreateKeyEx
here is how to call it

PHKEY pkey;
LPDWORD lpdword;
RegCreateKeyEx(HKEY_CURRENT_USER, NULL, 0,
               "High Voltage R\&D\\webmaster\\install_dir" ,
               REG_OPTION_NON_VOLATILE,
               KEY_ALL_ACCESS, &pkey, &lpdword);

0
 

Author Comment

by:4099aol
ID: 1182434
ok this

PHKEY pkey;
LPDWORD lpdword;
RegCreateKeyEx(HKEY_CURRENT_USER, NULL, 0, "High Voltage R\&D\\webmaster\\install_dir" , REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, &pkey, &lpdword);

would tell me what the value of the key is?? or will it run the application???
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182435
RegCreateKeyEx will create a key with no value
You call RegSetValue to set the value of the key

PHKEY pkey;
LPDWORD lpdword;
Char *keyvalue[] = "what ever";
RegCreateKeyEx(HKEY_CURRENT_USER, NULL, 0, "High Voltage R\&D\\webmaster\\install_dir" ,                       REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, &pkey, &lpdword);
RegOpenKey(HKEY_CURRENT_USER, NULL, &pkey);
RegSetValue(HKEY_CURRENT_USER, NULL, REG_SZ, keyvalue, 10);

the value 10 comes from the size in byte of the string - keyvalue.

0
 

Author Comment

by:4099aol
ID: 1182436
so this will create a blank reg key correct??

PHKEY pkey;
LPDWORD lpdword;
RegCreateKeyEx(HKEY_CURRENT_USER, NULL, 0, "High Voltage R\&D\\webmaster\\install_dir" , REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, &pkey, &lpdword);

and this will give it the value of "what ever"??

PHKEY pkey;
LPDWORD lpdword;
Char *keyvalue[] = "what ever";
RegCreateKeyEx(HKEY_CURRENT_USER, NULL, 0, "High Voltage
R\&D\\webmaster\\install_dir" , REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, &pkey, &lpdword);
RegOpenKey(HKEY_CURRENT_USER, NULL, &pkey);RegSetValue(HKEY_CURRENT_USER, NULL, REG_SZ, keyvalue, 10);
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182437
Ok, you got the create a blank key part correct

but, to give a key a value

you don't need the line RegCreateKeyEx(....)

Other than this, you got it
0
 

Author Comment

by:4099aol
ID: 1182438
so this will create the key and put the value in it?

PHKEY pkey;
LPDWORD lpdword;
Char *keyvalue[] = "what ever";
RegCreateKeyEx(HKEY_CURRENT_USER, NULL, 0, "High Voltage R\&D\\webmaster\\install_dir" , REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, &pkey, &lpdword); RegOpenKey(HKEY_CURRENT_USER, NULL, &pkey);RegSetValue(HKEY_CURRENT_USER, NULL, REG_SZ, keyvalue,10);
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182439
yeap
0
 

Author Comment

by:4099aol
ID: 1182440
please check the codes (which I just posted) I am reciving about 25-40 error messages.  I am using Borland C++ Builder v1.0
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182441
Can you put in above code line by line?
for example, put in
PHKEY pkey;
then compile, if it compiles fine
then put in the next line in

The codes works fine under visual C++

0
 

Author Comment

by:4099aol
ID: 1182442
Ok a { needs to be put somewhere in the third line...
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182443
oh, the third line should be
char keyvalue[] = "what ever";

* should not be in front of keyvalue
0
 

Author Comment

by:4099aol
ID: 1182444
There are a ton of errors!!! Starting with line four...
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1182445
Probably Borland builder does not have the command
RegCreateKeyEx
why don't you reject my answer, so that this question is open again.
0
 

Author Comment

by:4099aol
ID: 1182446
I will give u the credit for all of this time you spent.  I also need to change the question around a bit.


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

834 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