Jump to content
  • Advertisement
Sign in to follow this  

Need to get a value from the registry (C++)

This topic is 4392 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to get \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath from the registry, it is a REG_EXPAND_SZ. Anyone know how to do that, or at least the basic commands / libraries so I'll have something to lookup? Thanks

Share this post

Link to post
Share on other sites
I lookd up those functions, and it seems like it is going into the keys alright, but I can't get my data out from them.

Here is what I have:

HKEY *ptr1;
HKEY *ptr2;
HKEY *ptr3;
HKEY *ptr4;
HKEY *ptr5;
HKEY *ptr6;
BYTE *lpData;
LPDWORD lpcbData;
DWORD buffer_size = 1000;
long ec = 0;

memset(lpData, 0, sizeof(lpData));

if(ERROR_SUCCESS == RegOpenKeyEx(*ptr1, "CurrentControlSet", 0, KEY_READ, ptr2))
if(ERROR_SUCCESS == RegOpenKeyEx(*ptr2, "Services", 0, KEY_READ, ptr3))
if(ERROR_SUCCESS == RegOpenKeyEx(*ptr3, "Tcpip", 0, KEY_READ, ptr4))
if(ERROR_SUCCESS == RegOpenKeyEx(*ptr4, "Parameters", 0, KEY_READ, ptr5))
if(ERROR_SUCCESS == (ec = RegQueryValueEx(*ptr5, "DataBasePath", NULL, lpType, lpData, &buffer_size))){}
else cout<<"1Error"<<endl;
else cout<<"2Error"<<endl;
else cout<<"3Error"<<endl;
else cout<<"4Error"<<endl;
else cout<<"5Error"<<endl;
else cout<<lpData<<endl;

I am trying to figure it out looking at the MSDN but it doesn't really say how to put everything together.


Share this post

Link to post
Share on other sites
There's no need to step through each subkey, you can use the full registry path to access a key directly. See also the example on MSDN.

RegOpenKeyEx( HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\ ...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!