Document directory
- Programming for Windows System Automatic Login
Programming for Windows System Automatic Login
Principle:
You can modify the registry. Windows has a built-in automatic logon mechanism. When you log on to the system, Winlogon checks whether automatic logon is set in the registry. If you set it, the user name and password will be read and verified, log on to the system.
Method:
Registry key: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Winlogon
Key value:
Key Value |
Set Value |
Function |
AutoAdminLogon |
1; |
1 indicates automatic logon, 0 indicates automatic logon is disabled |
Defaultdomainname |
Set Value |
Domain name. leave it blank if it does not exist. |
DefaultUserName |
ABC |
Username used to log on to the system |
Defaultpassword |
123 |
The password used by the user name used to log on to the system. Delete this key value if you want to encrypt and save it. |
DontDisplayLastUsername |
1 |
|
Note: The following two key values must be deleted; otherwise, a notification dialog box is displayed.
- Legalnoticecaption
- Legalnoticetext
There are also two key values for the following functions:
- Ignoreshiftoverride ignores the Shift key. By default, the logon dialog box is displayed by pressing shift at startup (even if it is set to automatic logon). If it is set to 1, it is useless to press shift.
- Autologoncount
- Forceautologon: The value must be deleted.
Special note:
Because the password is stored in plain text, it is not safe, so a secret is provided in Windows to save the encrypted password, that is, in LSA. In sysinternals, The autologon tool saves the password. In Winlogon, it will first use "defaultpassword" in LSA, and then use this password. If it cannot be found, it will go to the Registry to find the "defaultpassword" value.
Read and Write LSA code, which is found in pinvoke.net. Original article:
Http://www.pinvoke.net/default.aspx/advapi32/DefaultPassword.html
Among them, C ++ code is provided by Microsoft: http://msdn.microsoft.com/en-us/library/aa378826 (vs.85). aspx
C # code: http://www.pinvoke.net/default.aspx/advapi32/LsaRetrievePrivateData.html
After obtaining the luautil class, you can call it as follows,
LSAutil lsa = new LSAutil("DefaultPassword");lsa.SetSecret(“abc”);Console.Write(lsa.GetSecret());