Can't read certain registry keys
-
Hi everyone, I am currently trying to read the following registry key in one of my programs:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName
I need to find out whether automatic logon is enabled on a machine or not, and reading whether above setting is empty or not seems to be the best way to do this. However, querying the value simple returns an empty string (though it definitely isn't empty); the code is working, as it works fine with other keys. So I guess that my program, for whatever reason, cannot access the Winlogon keys (other keys also don't work). Is there any workaround for this? Or any other way to find out if autologon is enabled? Hope anyone can shed some light on this, as it is driving me nuts right now :mad: I couldn't really find a better forum for this question; at least the program is written in C++, so... ;)
-
Hi everyone, I am currently trying to read the following registry key in one of my programs:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName
I need to find out whether automatic logon is enabled on a machine or not, and reading whether above setting is empty or not seems to be the best way to do this. However, querying the value simple returns an empty string (though it definitely isn't empty); the code is working, as it works fine with other keys. So I guess that my program, for whatever reason, cannot access the Winlogon keys (other keys also don't work). Is there any workaround for this? Or any other way to find out if autologon is enabled? Hope anyone can shed some light on this, as it is driving me nuts right now :mad: I couldn't really find a better forum for this question; at least the program is written in C++, so... ;)
Daniel 'Tak' M. wrote:
as it works fine with other keys.
Daniel 'Tak' M. wrote:
(other keys also don't work).
Which is it?
The difficult we do right away... ...the impossible takes slightly longer.
-
Daniel 'Tak' M. wrote:
as it works fine with other keys.
Daniel 'Tak' M. wrote:
(other keys also don't work).
Which is it?
The difficult we do right away... ...the impossible takes slightly longer.
The code works with other keys which are _not_ in Winlogon. Like HKLM\Software\Microsoft\Windows NT\CurrentVersion\Ports (read COM1:, retrieved the correct string).
-
The code works with other keys which are _not_ in Winlogon. Like HKLM\Software\Microsoft\Windows NT\CurrentVersion\Ports (read COM1:, retrieved the correct string).
OK. You might want to post the code you are using. Maybe we can see something wrong with it.
The difficult we do right away... ...the impossible takes slightly longer.
-
OK. You might want to post the code you are using. Maybe we can see something wrong with it.
The difficult we do right away... ...the impossible takes slightly longer.
Here it is (pretty straightforward):
HKEY hKey; if (RegCreateKeyEx(HKEY\_LOCAL\_MACHINE, "SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Winlogon", 0, NULL, REG\_OPTION\_NON\_VOLATILE, KEY\_READ, NULL, &hKey, NULL) == ERROR\_SUCCESS) { BYTE lpBuffer\[1024\]; DWORD dwType; DWORD dwBufferSize = 1024; if (RegQueryValueEx(hKey, "DefaultUserName", 0, &dwType, lpBuffer, &dwBufferSize) == ERROR\_SUCCESS) { ... } }
The query succeeds, but the buffer is simply empty (though the setting isn't); if I change Winlogon to "Ports" and the key name to "COM1:", I get the correct value.
-
Hi everyone, I am currently trying to read the following registry key in one of my programs:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName
I need to find out whether automatic logon is enabled on a machine or not, and reading whether above setting is empty or not seems to be the best way to do this. However, querying the value simple returns an empty string (though it definitely isn't empty); the code is working, as it works fine with other keys. So I guess that my program, for whatever reason, cannot access the Winlogon keys (other keys also don't work). Is there any workaround for this? Or any other way to find out if autologon is enabled? Hope anyone can shed some light on this, as it is driving me nuts right now :mad: I couldn't really find a better forum for this question; at least the program is written in C++, so... ;)
Are you working with the 32 or 64 bit version of Windows?
The difficult we do right away... ...the impossible takes slightly longer.
-
Are you working with the 32 or 64 bit version of Windows?
The difficult we do right away... ...the impossible takes slightly longer.
64 bit; the program is 32 bit, though.
-
64 bit; the program is 32 bit, though.
That might be the problem. Try calling
RegCreateKeyEx
as such:RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WOW64_64KEY, NULL, &hKey, NULL)
Use the
KEY_WOW64_64KEY
flag to indicate that you want to open the 64-bit view of the key.The difficult we do right away... ...the impossible takes slightly longer.
-
That might be the problem. Try calling
RegCreateKeyEx
as such:RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WOW64_64KEY, NULL, &hKey, NULL)
Use the
KEY_WOW64_64KEY
flag to indicate that you want to open the 64-bit view of the key.The difficult we do right away... ...the impossible takes slightly longer.
That did it! You really saved my day, Richard. My MSDN docs don't include that extra flag (VS 2005 still...), so I didn't know about it.
-
That did it! You really saved my day, Richard. My MSDN docs don't include that extra flag (VS 2005 still...), so I didn't know about it.
Glad I could help. :-D
The difficult we do right away... ...the impossible takes slightly longer.