Sign in to follow this  

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this