简体   繁体   中英

How to set to user account value “must not enter a user and password to use this computer” through c# code

如何设置用户帐户值“必须不输入用户名和密码才能使用此计算机”,在启动计算机时,用户不必通过c#代码插入用户名和密码

There are two ways of doing this, and both ways are fairly insecure.

One way to do it would be to clear out the password for the user, in which case, if it is the only user account on the system in Windows XP or higher, it will automatically log itself in.

The other way to do it, is to create three registry entries under HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon :

DefaultUserName (reg_sz): Set to the user's username
DefaultPassword (reg_sz): Set to the user's password
AutoAdminLogon (dword): Set to 1 to enable; 0 to disable

More information is available here: http://support.microsoft.com/kb/315231

Please be aware that this information is visible in the registry to anyone who has the ability to run the registry editor, so make sure the password is not something used elsewhere, or that the workstation is secure from other users.

To set this value through code, you can do the following:

        RegistryKey winlogonKey = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("CurrentVersion").OpenSubKey("WinLogon", true);
        winlogonKey.SetValue("DefaultUserName", "the_user's_username");
        winlogonKey.SetValue("DefaultPassword", "the_user's_password");
        winlogonKey.SetValue("AutoAdminLogon", 1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM