Page 1 of 1
Command line registry viewer (Win32 C++)
Posted: Mon Apr 04, 2005 9:33 am
by Hunter13
Hi, I need help with programming simple console registry viewer in c++. Im trying to get all keys, but no all subkeys as RegOpenKeyEx KEY_ENUMERATE_SUB_KEYS can. I dont want get out as
Code: Select all
Software
Microsoft
Current version
Security
etc
Sam
but i need to get just
Sofware
Security
Sam
+values
Can anybody help me make this function, which will fast read registry as DIR in cmd?
Re:Command line registry viewer (Win32 C++)
Posted: Tue Apr 05, 2005 11:09 pm
by Hunter13
Code: Select all
#include <windows.h>
#include <stdio.h>
void main()
{
char lszValue[100];
LONG lRet, lEnumRet;
HKEY hKey;
DWORD dwLength=100;
int i=0;
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\ADOBE", 0, KEY_READ , &hKey);
printf("HKEY_LOCAL_MACHINE\\SOFTWARE\\ADOBE\n\n");
if(lRet == ERROR_SUCCESS)
{
lEnumRet = RegEnumKey(hKey, i,lszValue,dwLength);
while(lEnumRet == ERROR_SUCCESS)
{
i++;
printf ("[%s]\n",lszValue);
lEnumRet = RegEnumKey(hKey, i,lszValue,dwLength);
}
}
}
soo easy
Re:Command line registry viewer (Win32 C++)
Posted: Wed Apr 06, 2005 8:03 am
by ark
Yeah, the above code is pretty much what you want to do, except that Platform SDK docs indicate that RegEnumKey exists for 16-bit compatibility, so you should really use RegEnumKeyEx, as in:
Code: Select all
#include <iostream>
#include <windows.h>
int main()
{
const int KeyNameBufferSize = 256;
LONG result = ERROR_SUCCESS;
TCHAR keyName[KeyNameBufferSize];
DWORD index = 0;
DWORD nameLength = KeyNameBufferSize;
FILETIME lastWriteTime;
std::cout << "Enumerating HKEY_LOCAL_MACHINE" << std::endl;
while (result == ERROR_SUCCESS)
{
nameLength = KeyNameBufferSize;
result = ::RegEnumKeyEx(HKEY_LOCAL_MACHINE, index, keyName,
&nameLength, 0, NULL, NULL, &lastWriteTime);
if (result == ERROR_SUCCESS)
{
std::cout << keyName << std::endl;
}
index++;
}
std::cout << "Done enumerating keys" << std::endl;
return 0;
}
(replace cout with printf as desired if not coding in C++).