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!

Reading the Registry

Status
Not open for further replies.

cpaige

Programmer
Jun 19, 2000
86
0
0
CA
I'm trying to read the registry using the API RegEnumValue<br>It seems to do really strange things. It only returns half the values or just one.&nbsp;&nbsp;All the other values it returns a ERROR_MORE_DATE.&nbsp;&nbsp;&nbsp;I have tried enlarging the buffer to 2k and I have also retreived the biggest value and dynamically sized the buffer based on that.<br><br>Has anyone ever run into this problem? Does any one have a sample code performing the same operation?&nbsp;&nbsp;I'm trying to read the keys&nbsp;&nbsp;&quot;HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run&quot;<br>and <br>HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices<br>&nbsp; <p>Clayton T. Paige<br><a href=mailto:cpaige@home.com>cpaige@home.com</a><br><a href= Snail</a><br>Clayton T. Paige<br>
Programmer Extraordinaire <br>
========================================================<br>
"Who General Failure? and Why is he reading my disk drive?"
 
Dear Clayton,<br><br>All that stuff is neatly wrapped up for you in the ATL CRegKey class. It is extremely lite and fast. Please look into using it for registry operations.<br><br>Good luck<br>-pete
 
Thanks for the info, but it doesn't help <br><br>I looked at the methods of CRegKey and found that it doesn't have one to retrieve a listing of values for a key. The RegEnumValue provides a list(with multiple calls) of all the values for a key.&nbsp;&nbsp;CRegKey doesn't provide this service.<br><br>I'm trying to get a listing of all the Run and Runservice Programs.<br><br>Do you have any other ideas? <p>Clayton T. Paige<br><a href=mailto:cpaige@home.com>cpaige@home.com</a><br><a href= Snail</a><br>Clayton T. Paige<br>
Programmer Extraordinaire <br>
========================================================<br>
"Who General Failure? and Why is he reading my disk drive?
 
Dear Clayton,<br><br>I apologize for the incomplete post earlier. Here is some sample code that uses RegEnumValue.<br><br>NOTE: sysformatMsg() is my helper function that wraps the FormatMessage() API for system error message. I left it in here to make the code more readable.<br><br>CListBox& _oList = (CListBox&)*((CListBox*)GetDlgItem(MYLIST));<br> CString buf;<br> const int BUF_SIZE = 255;<br> DWORD dwNameLen, dwReserved, dwType, dwDataLen;<br> dwNameLen = dwDataLen = BUF_SIZE;<br> int nIndex = 0;<br> CRegKey okey;<br> LONG lRet = okey.Open( HKEY_LOCAL_MACHINE, &quot;Software\\Microsoft\\WBEM&quot;);<br><br> if ( ERROR_SUCCESS != lRet){<br> sysformatMsg( buf, lRet);<br> AfxMessageBox( buf);<br> } <br><br> TCHAR pName[BUF_SIZE];<br> BYTE pData[BUF_SIZE];<br> ZeroMemory( pData, BUF_SIZE);<br><br> while ( ERROR_SUCCESS == (lRet =<br> RegEnumValue( okey, nIndex++, pName, &dwNameLen,<br> &dwReserved, &dwType, pData, &dwDataLen)) ){<br><br> switch( dwType){<br> case REG_EXPAND_SZ:<br> buf.Format(&quot;%s, %s&quot;, pName, (LPSTR)pData);<br> break;<br> default:<br> buf.Format(&quot;%s, DATA&quot;, pName);<br> break;<br> }<br> _oList.AddString(buf);<br> ZeroMemory( pData, BUF_SIZE);<br> dwNameLen = dwDataLen = BUF_SIZE;<br> }<br><br> if (ERROR_SUCCESS != lRet){<br> sysformatMsg( buf, lRet);<br> AfxMessageBox( buf);<br> }<br><br>Let me know if you have any questions.<br><br>Good luck<br>-pete<br><br>
 
Thanks for the code sample<br><br>It has some ideas that I might use.&nbsp;&nbsp;I did find the soultion on my own.&nbsp;&nbsp;I wasn't setting the size of the buffer valriable back to the max after I excuted the RegEnumValue.&nbsp;&nbsp;That gave the API an incorrect size and it didn't think there was enough space. <br><br>Thanks you for your help <p>Clayton T. Paige<br><a href=mailto:cpaige@home.com>cpaige@home.com</a><br><a href= Snail</a><br>Clayton T. Paige<br>
Programmer Extraordinaire <br>
========================================================<br>
"Who General Failure? and Why is he reading my disk drive?
 
I have been trying to access the registry in visual c++. Would you be able to send me the code you used to a do it?

Hope you can help


Andrew Gibson
Andy@relay.ie
 
Hey!

It has been almost a year since I was working with the registry ,so I don't remember everything I have done. I'll go look through my code and send it your way if I find it.

Clay :^) Clayton T. Paige
cpaige@home.com
Clayton T. Paige

Programmer Extraordinaire

========================================================

&quot;Who is General Failure? and Why is he reading my disk drive?&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top