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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems querying a value from the registry.

Status
Not open for further replies.

LuisEnrique

Programmer
Nov 15, 2001
10
0
0
US
Hello Everybody ok, here is my code:
HKEY keyHandle;
char *rgValue = NULL;
PLONG buffLen = NULL;
if(RegOpenKey( HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows\\CurrentVersion",
&keyHandle) == ERROR_SUCCESS)
{
//MessageBox(_T("Key was opened"));
RegQueryValue(keyHandle, "MediaPath", rgValue, buffLen );
MessageBox(rgValue);

}

What I want to do is to query the registry value of MediaPath and store it in the rgValue variable. I looked at it in MSDN and I did exactly that it says. I tryed a couple of times and nothing is being saved in rgValue. Have you guys had this problem before. What should I do? Am I missing something? Any anwer is more than welcome.

Have a good day,
 
Is your first statement evalueted to "ERROR_SUCCESS" .... if not then you need to create the key itsself.

Also you might be using Win32 apps and RegQueryValue is not compatible ..... This from MSDN:

"Win32-based applications should use the RegQueryValueEx function." So here's an example .....


DWORD size1;
DWORD Type;
RegQueryValueEx( HKEY_LOCAL_MACHINE, "MediaPath", NULL, &Type, // address of buffer for value type
(LPBYTE)&rgValue, // address of data buffer
&size1 // address of data buffer size
);
 
Also, I came across an annoying problem with these registry API's ......

if you donot specify the username/password and TRy using the microsoft scheduler to call this program. It doesn't work.

I havea program that works fine as long as it is run from command line or clicking on the .exe file.

But the same program doesn't run as expected. The scheduler calls this program but doesn't read or write to the registry.


In short: if you are writing a program that you will use MS Scheduler to call, then DON'T use the registry. Unless someone has a solution to this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top