Jump to content


  • 0
jamitupya

vbScript: Autologon from ini file

Question

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

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.