UnSetAutoLogon.ps1
<#PSScriptInfo
.VERSION 1.0 .GUID ff6a3fa1-a6e4-442f-a43d-c430bfb15f50 .AUTHOR SaGSA .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA .NOTES Author: SAGSA https://github.com/SAGSA Requires: Powershell 2.0 #> <# .DESCRIPTION UnSetAutologon #> try { $TestAdmin = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) $IsAdmin=$TestAdmin.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null function ButtonOk([string]$LabelText="Success") { $button_ok = New-Object -TypeName System.Windows.Forms.Button $button_ok.Size = New-Object -TypeName System.Drawing.Size(75,23) $button_ok.Location = New-Object -TypeName System.Drawing.Size(60,20) $button_ok.Text = 'OK' $button_ok.Add_Click({$Result=$button_ok.Text;$form.Close()}) $form=New-Object System.Windows.Forms.Form $form.Size = New-Object System.Drawing.Size(200,100) $form.StartPosition='CenterScreen' $form.MinimizeBox=$false $form.MaximizeBox=$false $form.Text=$LabelText $form.Controls.Add($button_ok) $form.AcceptButton = $button_ok $form.ShowDialog() } if ($IsAdmin) { try { Write-Verbose "Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\' -Name DefaultPassword" -Verbose Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\' -Name DefaultPassword -Force -ErrorAction Stop Write-Verbose "Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\' -Name AutoAdminLogon -Value 0" -Verbose Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\' -Name AutoAdminLogon -Value 0 -ErrorAction Stop ButtonOk } catch { Write-Error $_ ButtonOk -LabelText "Error" } } else { Write-Verbose "Administrator require..Running This Script As Administrator" -Verbose $ArgumentList=@( "-NoProfile" #"-WindowStyle Hidden" '-File '+'"'+$($MyInvocation.MyCommand.Definition)+'"' ) Write-Verbose "Start-Process -FilePath $env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -ArgumentList $ArgumentList -Verb runas" Start-Process -FilePath $env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -ArgumentList $ArgumentList -Verb runas -ErrorAction Stop } } catch { Write-Error $_ Start-Sleep -Seconds 10 } #$PsScriptRoot,$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition |