Programmatic implementation of Windows system automatic login
principle :
Implemented through registry modification. Windows built-in mechanism of automatic login, when logging on to the system, Winlogon will check the registry is not set to automatically login, if set up will read the user name and password, and then to verify, after the login into the system.
Method :
Registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Key values:
Key value |
Setting the value |
Role |
AutoAdminLogon |
1; |
1 means automatic login, 0 disables automatic logon |
DefaultDomainName |
Setting the value |
Domain name, if not, leave it blank |
DefaultUserName |
Abc |
User name used to log on to the system |
DefaultPassword |
123 |
Log in to the system using the user name of the password, if you want to encrypt the save to delete this key value |
DontDisplayLastUserName |
1 |
|
Note that the following two key values must be removed or a notification dialog box will be displayed.
- LegalNoticeCaption
- LegalNoticeText
There are also 2 key values, with the following functions:
- Ignoreshiftoverride ignores the SHIFT key, by default the login dialog box (even set to auto-login) is displayed by pressing SHIFT when you turn it on, and when you set it to 1, pressing the SHIFT key is useless.
- AutoLogonCount setting the number of automatic logins
- ForceAutoLogon the value to be dropped
Special attention :
Because the password is saved in plaintext and is not secure, Windows provides a secret place to save the encrypted password, which is in the LSA. The AutoLogon tool in Sysinternals is to keep the password in. In Winlogon, it will first go to the LSA to find the "DefaultPassword" information, found after the use of this password, if not found on the registry to find "DefaultPassword" value.
Read and write the LSA code, which is found in pinvoke.net. Original:
Http://www.pinvoke.net/default.aspx/advapi32/DefaultPassword.html
where C + + code is provided by Microsoft: http://msdn.microsoft.com/en-us/library/aa378826 (vs.85). aspx
C # code is: http://www.pinvoke.net/default.aspx/advapi32/LsaRetrievePrivateData.html
After obtaining the Luautil class, you can use it as a downward
Lsautil LSA = new Lsautil ("DefaultPassword"); LSA. Setsecret ("abc"); Console.Write (LSA. Getsecret ());
Http://www.cnblogs.com/greenerycn/archive/2009/11/18/windows_auto_logon.html
Programmatic implementation of Windows system automatic login