我有一台 Windows 10 計算機,它會在啟動時自動登入管理員帳戶來netplwiz
加載一些腳本,並且我需要在管理員帳戶登入後自動使用另一個使用者登入。
- 有沒有辦法從
powershell
or做到這一點cmd
?
答案1
你在尋找這樣的東西嗎?
電源外殼代碼:
$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