0

I have a script that get a file containing pc name and logged in automatically

this scenario works fine for local account but for domain account it won't work actually computer boot up network won't initialize thats why it shows error on pcs "No logon server is found" means no network but after 1 minute it works by manually when network got initialized please modify a little so that it may take a pause after restarting about "1 minute" and then start logged in process (when network got initialize properly) below is the script

Set objFSO = CreateObject("Scripting.FileSystemObject") 
set objShell = wscript.CreateObject("wscript.shell")
const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
sUserName = InputBox("enter user name")
sPassword = InputBox("enter the password for the user")
Set oTS = objFSO.OpenTextFile("path of my txt file") 
Do Until oTS.AtEndOfStream
strComputer = oTS.ReadLine
On Error Resume Next
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")

sRegPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ' oReg.SetStringValue HKEY_USERS,strKeyPath,strValueName,strValue oReg.SetStringValue HKEY_LOCAL_MACHINE,sRegPath,"AutoAdminLogon",1 oReg.SetStringValue HKEY_LOCAL_MACHINE,sRegPath,"DefaultUserName",sUserName oReg.SetStringValue HKEY_LOCAL_MACHINE,sRegPath,"DefaultPassword",sPassword

'objShell.Run "shutdown.exe /R /T 5 /C" objShell.Run "C:\Windows\System32\shutdown.exe /m \" & strComputer & " -r " Loop MsgBox ("Successfully Logged On values Set") oTS.Close WScript.Quit

Your kind help will be highly appreciated

grawity
  • 501,077

2 Answers2

0

Your problem is not in the script but how it is setup. The registry hack you use to setup auto login works differently when the PC is domain joined. First of all, you have to use DOMAIN\username to login with a domain user, and the only reliable way I found out to get this to work is by using the program netplwiz

If you have setup automatic logon using the registry key, netplwiz should give you the ability to check a checkbox and enter login credentials. After unchecking and checking then hit apply, and entering the correct login credentials, it should then create the correct registry values. If you incorporate those in your script, it should work.

LPChip
  • 66,193
0

Definitely look at what LPChip is saying, but for the part about a delay in execution, you can do a loop with DoEvents. Something like:

numSeconds = 120
StartSecond = Now
EndSecond = DateAdd("s", numSeconds, Now)
While Now < EndSecond
 DoEvents
Wend

I would probably include a test to see if the network is up inside the loop and maybe exit execution if the network does not come up.

Yorik
  • 4,988