-
-
Save p0w3rsh3ll/aea6680c7daeedf23144b4fcb23e71aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@' | |
$desk = -join "$($env:computername)"[-2..-1] | |
$key = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' | |
& (Get-Command "$($env:systemroot)\system32\reg.exe") @('delete',"$($key)",'/v','AutoLogonCount','/f') | |
& (Get-Command "$($env:systemroot)\system32\reg.exe") @('delete',"$($key)",'/v','AutoLogonChecked','/f') | |
& (Get-Command "$($env:systemroot)\system32\reg.exe") @('add',"$($key)",'/v','DefaultUserName','/t','REG_SZ','/d',"MyUserPrefix$($desk)",'/f') | |
& (Get-Command "$($env:systemroot)\system32\reg.exe") @('add',"$($key)",'/v','DefaultPassword','/t','REG_SZ','/d','""','/f') | |
& (Get-Command "$($env:systemroot)\system32\reg.exe") @('add',"$($key)",'/v','DefaultDomainName','/t','REG_SZ','/d','MyDomainName','/f') | |
& (Get-Command "$($env:systemroot)\system32\reg.exe") @('add',"$($key)",'/v','AutoAdminLogon','/t','REG_SZ','/d','1','/f') | |
& (Get-Command "$($env:systemroot)\system32\reg.exe") @('add',"$($key)",'/v','ForceAutoLogon','/t','REG_DWORD','/d','0x1','/f') | |
'@ | Out-File 'C:\Windows\autologon.ps1' -Encoding 'Ascii' | |
try { | |
$errHT = @{ ErrorAction = 'Stop' } | |
$aHT = @{ | |
Execute = 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' | |
Argument = '-Exec Bypass -File "C:\Windows\autologon.ps1"' | |
} | |
$HT = @{ | |
TaskName = 'Set-AutoLogon' | |
User = 'S-1-5-18' #'nt authority\system' | |
Force = [switch]::Present | |
Action = (New-ScheduledTaskAction @aHT @errHT) | |
} | |
Register-ScheduledTask @HT @errHT | |
Write-Verbose -Message "Successfully registered autlogon scheduled task" -Verbose | |
} catch { | |
Write-Warning -Message "Failed to register autologon scheduled task because $($_.Exception.Message)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment