Skip to content

vbScript: Autologon from ini file

Featured Replies

This script will load a command line variable for the username or can auto to administrator and password from an ini file.

 


' Initialization

Set wshNetwork = CreateObject("WScript.Network")
Set shell = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")


' Get parameters
Program = "AutoLog.vbs"

If WScript.Arguments.Count > 0 then
   username = WScript.Arguments.Item(0)
Else
   username = TranslateLocalUser("Administrator")
End if
If WScript.Arguments.Count > 1 then
   password = WScript.Arguments.Item(1)
Else
   password = ReadIni("C:\Build\Settings.ini", "LocalAdmin", "localAdminPassword")
End if
computerName = wshNetwork.ComputerName


' Set the AutoAdminLogon registry keys

shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon", "1", "REG_SZ"
shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName", username, "REG_SZ"
shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName", computerName, "REG_SZ"
shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword", password, "REG_SZ"
shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoLogonCount", &H00000005, "REG_DWORD"



' READINI ( file, section, item )
' file = path and name of ini file
' section = [section] must not be in brackets
' item = the variable to read

 

 


[LocalAdmin]
localAdminPassword=password

 

 

Usage:

cscript.exe //nologo c:\build\Autolog.vbs

 

 

 

 

 

Remove AutoLogon


' Initialization
Program = "DelAuto.vbs"

Set shell = CreateObject("WScript.Shell")

' Clean up registry keys

shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon", "0", "REG_SZ"
shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName", "", "REG_SZ"
shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName", "", "REG_SZ"
shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword", "", "REG_SZ"
shell.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoLogonCount", &H00000000, "REG_DWORD"

 

 

 

Usage:

cscript.exe //nologo c:\build\DelAuto.vbs

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.