Hi,
Could any one tell me how could I get the valaue of below registry key on remote machine and get the value of sub key DefaultUserName?
HKEY key;
RegOpenKeyEx(HKEY_LOCAL_MACHINE "SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\Winlogon",0,KEY_QUERY_VALUE,&hKey );
I am going crazy behind this stuffs. I have done below tasks till now. Please refer my below programming pieces and let me know what wrong I am doing? There is no syntax or any logical errors.
The below portion connects remote host's LOCAL_MACHINE_KEY successfully.
HKEY lHKeyhandle;
HKEY lhkey;
LONG lRetVal;
CharArray rhost(30); //CharArray is my user defined class
rhost.buf = strDup("\\\\");
strcat(rhost.buf,remoteHost.buf);
MessageBox(0,rhost.buf,"info",MB_OK); /*****This displays \\remote_hostname correctly******/
lRetVal = RegConnectRegistry(rhost.buf, HKEY_LOCAL_MACHINE, &lHKeyhandle);
if(lRetVal == ERROR_SUCCESS) {
MessageBox(0,"Successfully connected","info",MB_OK); /*****This message box got displayed.****/
}
below code enumerate the LOCAL_MACHINE_KEY handle to all subkeys
{HARDWARE,SAM,SECURITY,SOFTWARE,SYSTEM} correctly.
LONG rc; // contains error value returned by Regxxx()
LPTSTR MachineName=NULL;
DWORD dwSubKeyIndex=0; // index into key
char szSubKey[_MAX_FNAME]; .
DWORD dwSubKeyLength=_MAX_FNAME; // length of SubKey buffer
while((rc=RegEnumKeyEx(
lHKeyhandle,
dwSubKeyIndex,
szSubKey,
&dwSubKeyLength,
NULL,
NULL,
NULL,
NULL)
) != ERROR_NO_MORE_ITEMS) {
if(rc == ERROR_SUCCESS) { dwSubKeyIndex++; dwSubKeyLength=_MAX_FNAME;
MessageBox(0,szSubKey,"info",MB_OK);
}
}
My purpose is to get the value of "SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\Winlogon\\DefaultUserName" registry key. For that I have written below code to connect "SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\Winlogon" and then I will use RegEnumKeyEx function to enumerate all sub keys.
lRetVal = RegOpenKeyEx(lHKeyhandle, "SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\Winlogon", 0, KEY_ALL_ACCESS, &lhkey);
if(lRetVal == ERROR_SUCCESS) {
/***** Not comming here ***********/
MessageBox(0,"Successfully opened key","info",MB_OK);
RegCloseKey(lHKeyhandle);
} else {
/***** display this message*****/
//"GetLastError() returns 997 code"
MessageBox(0,"Could not open key","info",MB_OK);
}
I dont understand why RegOpenKeyEx getting failed? Could anyone tell me how could I make it works?
Thanks in advanced,
Megha