![有没有办法从 powershell 或 cmd 切换用户?](https://linux22.com/image/1587081/%E6%9C%89%E6%B2%A1%E6%9C%89%E5%8A%9E%E6%B3%95%E4%BB%8E%20powershell%20%E6%88%96%20cmd%20%E5%88%87%E6%8D%A2%E7%94%A8%E6%88%B7%EF%BC%9F.png)
我有一台 Windows 10 机器,它在启动时自动登录管理员帐户以netplwiz
加载一些脚本,并且我需要在管理员帐户登录后自动以另一个用户身份登录。
- 有没有办法从
powershell
或做到这一点cmd
?
答案1
您在寻找类似的东西吗?
POWERSHELL代码:
$Username = 'UserX'
$Password = 'P@ssW0rd'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force #Not recommended, but if rights are set on that location you can use it like this, otherwise encrypt it (recommended).
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
#You can use it like this, or use it with other commands and ' -Credential ...'
Invoke-Command -ComputerName "DeviceName" -Credential $Cred -ScriptBlock {#Your Code}
答案2
如果您想在管理员登录后通过代码更改自动登录,您可以使用以下命令:
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Set-ItemProperty $RegPath "AutoAdminLogon" -Value "1" -type String
Set-ItemProperty $RegPath "DefaultUsername" -Value "User-1 -type String
Set-ItemProperty $RegPath "DefaultPassword" -Value "Password" -type String