This script will set the appropriate registry keys to auto-logon a server. This would be handy when wanting to do something that would require the server to auto-logon, run a script and reboot. This script could also be used to disable auto-logon, just set the AutoLogonCount=0. Be very careful when running this script, as the dis-claimer, backup your registry before running. If your not comfortable in how or why to use this script, don't use it then. This can be saved in a file (autologon.vbs computer1 computer2 etc..) This accepts any number of arguments. The argument would set the DefaultDomainName to the local computer name, login as the local Administrator and run the script. Definitely test out the script on a development machine before using. Option Explicit On Error Resume Next Err.Clear
dim StdOut, objReg, strKeyPath, strStringValueName, strSetStringValue, strEntryName, strValue, strLoginPath dim Wshshell, ArgObj, sArgCount, x
Set WshShell = WScript.CreateObject("WScript.Shell")
const HKEY_LOCAL_MACHINE = &H80000002 Set StdOut = WScript.StdOut
strSetStringValue = "c:\winnt\system32\wscript.exe c:\someWSHFile.vbs" strStringValueName = "Description of the process"
Set ArgObj = WScript.Arguments sArgCount = ArgObj.Count
For x = 0 to sArgCount - 1 Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ ArgObj(x) & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\ANewRegistryKey" strLoginPath = "Software\Microsoft\Windows NT\CurrentVersion\Winlogon" objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath objReg.SetStringValue HKEY_LOCAL_MACHINE, strLoginPath, "AutoAdminLogon", "1" objReg.SetStringValue HKEY_LOCAL_MACHINE, strLoginPath, "DefaultUserName", "Administrator" objReg.SetStringValue HKEY_LOCAL_MACHINE, strLoginPath, "DefaultPassword", "Password" objReg.SetStringValue HKEY_LOCAL_MACHINE, strLoginPath, "AutoLogonCount", "1" objReg.SetStringValue HKEY_LOCAL_MACHINE, strLoginPath, "DefaultDomainName", ArgObj(x) objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strStringValueName, strSetStringValue set objReg = Nothing Next
set wshshell = nothing set argobj = nothing
Sub ErrorHandler(byVal errornum, byVal errorDesc) theDesc = "Error Number: " & errornum & " Error Description: " & errorDesc WshShell.LogEvent 1, theDesc err.clear End Sub |