Sign in to follow this  
Followers 0
trids

How to reboot?

8 posts in this topic

I'm using AI3 to autopilot a setup process, which needs a reboot halfway through. Any ideas on how to accomplish this with one script on NTWS4?

In the interests of minimal human intervention, I'd like to avoid the obvious of having the user fire two scripts: the first one steering the process through until the reboot; the next one he starts after the reboot has completed and he has logged in again (with Administrator authority).

:whistle:

If there isn't any simple way to achieve this, then two scripts it will have to be.

TIA

Share this post


Link to post
Share on other sites



Below a porton of a script I use to install software in steps with reboots in between... more or less like Larry described..

jos

; pgm name DEMO.AU3

$Userid="Administrator"

$Psw="adminpsw"

; Remove autologin params from registry to clean up

SetAutoLogon("Off", "")

;

; retrieve param

$param1 = ""

If $CmdLine[0] > 0 then

$param1 = $CmdLine[1]

endif

; Act on it

Select

Case $param1 = ""

; run your programs with admin account if needed in the first step

RunAsSet($userid, @Computername, $psw)

;

; *** put your stuff here for step1 ***

RunWait("notepad.exe step1.txt")

;

SetAutoLogon("On", "step1")

Shutdown(6)

Case $param1 = "step1"

; is already logged on with admin account

;

; *** put your stuff here for step2 ***

RunWait("notepad.exe step2.txt")

;

SetAutoLogon("On", "step2")

Shutdown(6)

Case $param1 = "step2"

; logoff the admin account

; *** put your stuff here for step3 ***

RunWait("notepad.exe step3.txt")

; just logoff

Shutdown(0)

Exit

EndSelect

exit

;

;

Func SetAutoLogon($sw,$step)

If $sw = "On" Then

; set the registry to start this program again after reboot

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "Demo", "REG_SZ", @ScriptFullPath & " " & $step)

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\","AutoAdminLogon","REG_SZ","1")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\","DefaultDomainName", "REG_SZ",EnvGet("LOGONSERVER"))

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\","DefaultUserName", "REG_SZ",$Userid)

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\","DefaultPassword", "REG_SZ",$Psw)

EndIf

;

If $sw = "Off" Then

; Remove the registrykey to start this program again after reboot

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "Demo")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\","AutoAdminLogon","REG_SZ"," ")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\","DefaultDomainName", "REG_SZ"," ")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\","DefaultUserName", "REG_SZ"," ")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\","DefaultPassword", "REG_SZ"," ")

EndIf

EndFunc


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
:whistle: That's excellent - just what I'm after .. thanks guys!

Share this post


Link to post
Share on other sites

Thanks again to Larry and JdeB for showing me how to get the reboot to work! But now .. I'm struggling a bit trying to get pass-2 of the script to fire after successfully rebooting. :whistle:

The setup that I'm auto-piloting hijacks the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN for it's own purposes, and I can't seem to get it to also launch pass-2 of my script .. so I was thinking I might use Larry's alternative of putting a shortcut in the startup folder instead.

I guess I would use the FileCreateShortcut function: but should I put the commandline parameter to the script in the "file" specification along with the au3 reference (option-1 below)? Or in the "args" specification (option-2 below)?

;Option-1
FileCreateShortcut (@ScriptFullPath & " pass2", @StartupDir & "\autopilot.lnk")

;Option-2
FileCreateShortcut (@ScriptFullPath, @StartupDir & "\autopilot.lnk", "", "pass2", "", "", "")

.. Or is there another tree I should be barking up?

- TIA

Share this post


Link to post
Share on other sites

OK gottit - ;o) .. option-2 is the only one that produces usable results so far.

Share this post


Link to post
Share on other sites

trids,

what seems to be the issue running your script after reboot ?

maybe you can post or sent me your script then I'll have a look..

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

There also is a registry entry

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUNONCE

where you can write the 2nd script details. It will run once and delete the relevant data from the registry.

Another idea if you are running on a network is to assign a login script to the relevant user and run the second script from there.

Cheers


CheersNobby

Share this post


Link to post
Share on other sites

In the end, I'm creating a shortcut in @StartupDir as Larry suggested, and deleting it in the second pass. Works very nicely indeed. Thanks for all the ideas folks :whistle:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0