Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening the registry to obtain string values 1

Status
Not open for further replies.

bikermouse

Programmer
Joined
Dec 21, 2002
Messages
16
Location
US
Regarding using the registry,
does anyone know how to retrive string values (address paths) from REG_SZ keys

here's what Ive got so far

RegOpenKeyEx(HKEY_CLASSES_ROOT,"CLSID",0,KEY_ALL_ACCESS,&hkey);

RegQueryValueEx(????????????????);
RegCloseKey(hkey);

"CLSID" can be replaced with say "BryceScene" or whathave you and the registry appears to open and close but I am unable to get the Query function to operate right.

any help?
Thanks,
- TJ




 
Try so:
HKEY myKey = NULL;
char stringToRead[1024]; //You should have enough memory here
int cbBufferSize = 1023;
DWORD dwType = REG_SZ;
//Read only
int err = RegOpenKeyEx(HKEY_CLASSES_ROOT, "KeyYouWishToOpen", 0, KEY_QUERY_VALUE, &myKey);
if(err == 0)
err = RegQueryValueEx(myKey, "SubKeyWitchValueYouWishToRead", 0, &dwType, stringToRead, &cbBufferSize);
RegCloseKey(myKey);

"KeyYouWishToOpen" - You must enter full path to Your key, for example: "SYSTEM\\CurrentControlSet\\Services\\lanmanserver\\parameters"
If You are not Administrator (Win NT/2000/XP), You probably do not have write access to registry.
 
tchouch,
Thank you. I'll try this. It looks as though it should work.
at this point I only need read access.
- TJ
 
tchouch,
I got it to work like this - it doesen't seem to like two calls to hkey both refering to query at the same time, so I was forced to do it this way, but this seems neater anyway.
(this example finds bryce5.exe path from the .br5 extention)

Again thank you for your help.
- TJ
////////////////////////////////////////////////////////////int readkey(char * keyname);
extern char strang[];
///////////////////////////////////////////////////////////////////////////////////////
int manipulate()
{
char strang2[1024];
int rv;

rv = readkey(".br5");
if(rv != 13) return rv;
strcpy(strang2,strang);
strcat(strang2,"\\Shell\\open\\command");
strang[0]= 0;
rv = readkey(strang2);
return rv;
}
////////////////////////////////////////////////////////////
int readkey(char * keyname)
{
if(keyname == NULL)
{
return 10;
}
else
{
HKEY hkey = NULL;
DWORD dwType = REG_SZ;
int cbBufferSize = 1023;
if(RegOpenKeyEx (HKEY_CLASSES_ROOT,keyname,0,KEY_QUERY_VALUE,&hkey ) != ERROR_SUCCESS)
{
return 11;
}
if(RegQueryValueEx(hkey,"",0,&dwType,strang,&cbBufferSize) != ERROR_SUCCESS)
{
RegCloseKey (hkey);
return 12;
}
RegCloseKey(hkey);
}
return 13;
}
////////////////////////////////////////////////////////////
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top