浏览代码

exit after disabling

Tobias Simetsreiter 2 年之前
父节点
当前提交
954a725be0
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      bin/Set-AutoLogin.ps1

+ 12 - 2
bin/Set-AutoLogin.ps1

@@ -1,6 +1,8 @@
 param(
     $Username = $null,
-    $Pass = $null
+    $Pass = $null,
+    [Parameter(HelpMessage="Disables AutoLogin")]
+    [switch]$Disable = $false
 )
 
 ### The code below configures Auto-Login on Windows computers ###
@@ -12,7 +14,16 @@ Web: https://sid-500.com
  
 #>
 
+$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
+
 hostname
+
+if ($Disable) {
+    Set-ItemProperty $RegistryPath 'AutoAdminLogon' -Value "0" -Type String
+    Get-ItemProperty $RegistryPath 'AutoAdminLogon'
+    exit
+}
+
 if ($null -eq $Username){
     $Username = Read-Host 'Enter username for auto-logon (f.e. contoso\user1)'
 }
@@ -24,7 +35,6 @@ if ("" -eq $Username) {
 if ($null -eq $Pass){
     $Pass = Read-Host "Enter password for $Username"
 }
-$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
 Set-ItemProperty $RegistryPath 'AutoAdminLogon' -Value "1" -Type String 
 Set-ItemProperty $RegistryPath 'DefaultUsername' -Value "$Username" -type String 
 Set-ItemProperty $RegistryPath 'DefaultPassword' -Value "$Pass" -type String