有没有办法从 powershell 或 cmd 切换用户?

有没有办法从 powershell 或 cmd 切换用户?

我有一台 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

相关内容