Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script To Rename PC and Autologon

Status
Not open for further replies.

BobHunter

Programmer
Mar 26, 2001
62
0
0
GB
I have a base PC setup which successfully autologons. The below script changes the PC name and user accounts and should also make it auto logon.

After the script is run, it does not autologon, but if I manually enter the password it does login proving the account and password have been renamed successfully.

Running the script again and changing the name back to the original base PC name works, i.e. it will then successfully autologon again.

I have checked HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon and all is in order after the the script is ran.

What I am confused about is that after the rename - the renamed accounts exist and I can manually login with them. If I use control userpasswords2 - it's setup to autologin. If I uncheck and recheck the checkbox and enter the password it will THEN autologon but there are no visible changes to the registry ?

Any ideas ? I'm very confused/annoyed !



Set wshShell = WScript.CreateObject("WSCript.Shell")

CurrentTag = wshShell.RegRead("HKCU\Volatile Environment\USERNAME")

AssetTag=InputBox("Enter Asset Tag :", "Rename PC")
Password=Replace(AssetTag,"IT_","Pa5W0Rd")
response = MsgBox("This utility will convert this PC to " & assettag & " with a password of " & Password & ". Press OK to continue.",1,"Rename PC")

if response = 1 then

CommandLineText="cusrmgr -u " & CurrentTag &" -P " & Password
response = WshShell.Run ("CMD /c" & CommandLineText,,True)

CommandLineText="cusrmgr -u " & CurrentTag &" -r " & AssetTag
response = WshShell.Run ("CMD /c" & CommandLineText,,True)

WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUsername", AssetTag, "REG_SZ"
WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword", Password, "REG_SZ"
WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName", AssetTag, "REG_SZ"

WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", AssetTag, "REG_SZ"
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName", AssetTag, "REG_SZ"

WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", AssetTag, "REG_SZ"
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname", AssetTag, "REG_SZ"
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet001\Services\Tcpip\Parameters\NV Hostname", AssetTag, "REG_SZ"
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet001\Services\Tcpip\Parameters\Hostname", AssetTag, "REG_SZ"
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet002\Services\Tcpip\Parameters\NV Hostname", AssetTag, "REG_SZ"
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet002\Services\Tcpip\Parameters\Hostname", AssetTag, "REG_SZ"

response = MsgBox("Done. Press OK to Reboot !",0,"Rename PC")

CommandLineText="shutdown /r /t 0"
response = WshShell.Run ("CMD /c" & CommandLineText,,True)

end if

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top