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

ReadinReg

Status
Not open for further replies.

XerxesTheMighty

Programmer
Jun 15, 2003
72
US
How can I read a value in the registry?
I've tried RegQueryValue and -Ex, SHGetValue, SHQueryValue, etc. All of these I looked up on MSDN and found that I'm using them right, but the compiler doesn't like it. For instance on SHGetValue, it tells me to put in the 4th slot the type of value to get (I.E. REG_SZ). But when I compile it, the error tells me something like const int to unsigned long--but according to MSDN, that isn't right. Anyway, I finally get RegQueryValue to work and compile and it doesn't store any thing to the string I assigned it. I made sure the path exists in the registry. So the question still stands:
How can I read a value from the registry and store it to a string?

--------------
"Ask a question and your a fool for three minutes, don't ask it and your a fool for a lifetime." -Chinese Proverb

Xerxes Dynatos
 
hi,

try to user MFC class CRegKey.

CRegKey regKey;
CString temp;
TCHAR sz[100];

if(regKey.Open(HKEY_LOCAL_MACHINE,temp,KEY_ALL_ACCESS)!=0)
{
//Error
}
temp.Format(_T("MyValue"));
if(regKey.QueryValue(sz,temp,&size) != ERROR_SUCCESS)
{
//Error.
}

regKey.Close();

if u find useful then notify me.
 
first use RegOpenKey and after that use RegQueryValue

Ion Filipski
1c.bmp
 
neither work:
RegQueryValue gives a GPF and freezes the sytem (I first used the RegOpenKey).

--------------
"Ask a question and your a fool for three minutes, don't ask it and your a fool for a lifetime." -Chinese Proverb

Xerxes Dynatos
 
What version of Windows are you on? Have you tries oening HKEY_LOCAL_USER?
 
XP Home&Pro.
It'll open it, and I can write to it--it just won't READ it.

--------------
"Ask a question and your a fool for three minutes, don't ask it and your a fool for a lifetime." -Chinese Proverb

Xerxes Dynatos
 
It don't matter what I do, when the program reaches to the code of RegQueryValue or -Ex, it crashes and gives an error message from Windows to close it.

--------------
"Ask a question and your a fool for three minutes, don't ask it and your a fool for a lifetime." -Chinese Proverb

Xerxes Dynatos
 
Maybe you can try RegEnumValue, It works well in my recent project, although I remember RegQueryValueEx also worked when I used some time ago.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top