Solved

Help!

Posted on 1998-02-17
17
192 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 20 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

762 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

18 Experts available now in Live!

Get 1:1 Help Now