Sign in to follow this  
Followers 0
sakshi

Reboot using autoit

15 posts in this topic

In my script i need to reboot the PC in between,

and then the script should pause or sleep

and when PC restarts then it should start again.

how can i do this?

please help?

thanks.

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

In my script i need to reboot the PC in between,

and then the script should pause or sleep

and when PC restarts then it should start again.

how can i do this?

please help?

thanks.

This might help. Or use the Advanced Search function and search for "reboot" with "Search titles only" tagged. Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

By writing to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run or HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.

And using command line options (switches).

edit: or do what water said.

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You have to do more than that. Since Sakshi used the term pause or sleep, I assume they wanted to continue where the script left off. This will just cause the script to run again from scratch when windows restarts.

If you want to jump to where you left off you need to set some thing you can test to see if it is running the 1st time or after the reboot. This can be done in probably an infinite amount of ways depending on what your script does or changes the 1st time it is run. Or you could always just call it with a parameter when you make the registry addition and do something different based on that. Remember though that none of the variables from the 1st run will be in memory after the computer restarts so if any are needed for the 2nd run you need to find them again or store them somewhere before the restart.

Edit: Actually trancexx did say "And using command line options (switches)." I guess he caught that too.

Edited by ShawnW

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I am currently working on a program that requires reboots and the program has to pickup basically were it left off. I do not know if this will help you but what I did was used Select/case with settings.ini file that holds my important variables that I will need after the reboot.

Example of how I did it.

$prog = IniRead (@ScriptDir & "\config.ini", "Installation_Progress", "Progress", "");;reads the progress of the installation
$Progress = int ($prog);;I found(with help) that you will need to change the value to integer, if you do not it will not work after reboot 


Select
     Case $Progress < 1
          ;;This is were I put my code for the begining of the script/program
          IniWrite (@ScriptDir & "\setting.ini", "Installation_Progress", "Progress", "1")

     Case $Progress = 1
          ;;This is were I put my code for the first reboot
          IniWrite (@ScriptDir & "\setting.ini", "Installation_Progress", "Progress", "2")
     Case $Progress = 2
          ;;And code for second reboot
          IniWrite (@ScriptDir & "\setting.ini", "Installation_Progress", "Progress", "3")

EndSelect

and you could continue case for as many reboots needed.

This is just a suggestion. May or may not help.

forgot to mention that i was using trancexx's method to recall the program durring reboot with a progressbar and 1 min worth of sleeps

$prog = IniRead (@ScriptDir & "\config.ini", "Installation_Progress", "Progress", "");;reads the progress of the installation
$Progress = int ($prog);;I found(with help) that you will need to change the value to integer, if you do not it will not work after reboot 


Select
     Case $Progress < 1
          ;;This is were I put my code for the begining of the script/program
          IniWrite (@ScriptDir & "\setting.ini", "Installation_Progress", "Progress", "1")
          RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "ScannerSetup", "REG_SZ",@ScriptDir & "\setup_.bat")
     Case $Progress = 1
          ;;Example of my common code
          ProgressOn ("Scanner Installation Step 4", "Installation Will continue", "0 Complete")
      For $i = 1 to 100 step 1
        sleep(300)
        ProgressSet( $i, $i & " Complete")
      Next
      ProgressSet(100 , "Done", "Complete")
      sleep(2000)
      ProgressOff()
          ;;This is were I put my code for the first reboot
          IniWrite (@ScriptDir & "\setting.ini", "Installation_Progress", "Progress", "2")
        
     Case $Progress = 2
          ;;Example of my common code
          ProgressOn ("Scanner Installation Step 4", "Installation Will continue", "0 Complete")
      For $i = 1 to 100 step 1
        sleep(300)
        ProgressSet( $i, $i & " Complete")
      Next
      ProgressSet(100 , "Done", "Complete")
      sleep(2000)
      ProgressOff()
          ;;And code for second reboot
          IniWrite (@ScriptDir & "\setting.ini", "Installation_Progress", "Progress", "3")
          Regdelete ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "ScannerSetup")
EndSelect

I think that is all of it.

Edited by damon

It always amazes me how one little thing can cause so much havoc

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

In my script i need to reboot the PC in between,

and then the script should pause or sleep

and when PC restarts then it should start again.

how can i do this?

please help?

thanks.

StartUP_RegWriteL("Notepad",@SystemDir & "\Notepad.exe")

Func StartUP_RegWriteL($Prog_Name,$Prog_FllPtch)
if _
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
$Prog_Name, "REG_SZ", $Prog_FllPtch) Then Return True
Return False
EndFunc

Func StartUP_RegWriteC($Prog_Name,$Prog_FllPtch)
if _
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", _
$Prog_Name, "REG_SZ", $Prog_FllPtch) Then Return True
Return False
EndFunc

WM_QUERYENDSESSION Message

http://msdn.microsoft.com/en-us/library/aa376890%28v=VS.85%29.aspx

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Const $ENDSESSION_CLOSEAPP = 0x00000001
;ENDSESSION_CLOSEAPP
;The application is using a file that must be replaced, the system is being
;serviced, or system resources are exhausted. For more information, see Guidelines
;for Applications.
Const $ENDSESSION_CRITICAL = 0x40000000
;ENDSESSION_CRITICAL
;The application is forced to shut down.
Const $ENDSESSION_LOGOFF = 0x80000000
;ENDSESSION_LOGOFF
;The user is logging off. For more information, see Logging Off.
Const $WM_QUERYENDSESSION = 0x0011
;http://msdn.microsoft.com/en-us/library/aa376890%28v=VS.85%29.aspx

GUICreate("",0,0,0,0)
GUIRegisterMsg($WM_QUERYENDSESSION, "WM_QUERYENDSESSION")
While 1
WEnd

Func WM_QUERYENDSESSION($hWnd, $Msg, $wParam, $lParam)
Switch $lParam
Case $ENDSESSION_CLOSEAPP
MsgBox(0,"MSG","ENDSESSION_CLOSEAPP")
Case $ENDSESSION_CRITICAL
MsgBox(0,"MSG","ENDSESSION_CRITICAL")
Case $ENDSESSION_LOGOFF
MsgBox(0,"MSG","ENDSESSION_LOGOFF")
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Another example I posted already a couple of times which worked for me with several software roll-outs that required to be logged-on as LocalAdmin and reboots.

; pgm name Install_With_Reboots.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      
        ; *** put your stuff here for step1 ***
        RunAs($Userid, @ComputerName, $Psw, Default,"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)
    Local $s1, $s2, $s3, $s4
    If $sw = "On" Then
        ; set the registry to start this program again after reboot
        ; Read  current settings
        $s1 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "AutoAdminLogon")
        $s2 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultDomainName")
        $s3 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName")
        $s4 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultPassword")
        ;Save current settings
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_AutoAdminLogon", "REG_SZ", $s1)
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultDomainName", "REG_SZ", $s2)
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultUserName", "REG_SZ", $s3)
        RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultPassword", "REG_SZ", $s4)
        ;Set New Settings
        RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "AutoItInstaller", "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
        ; Read  previous settings and reset 
        $s1 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_AutoAdminLogon")
        If Not @error Then 
            RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_AutoAdminLogon")
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "AutoAdminLogon", "REG_SZ", $s1)
        EndIf
        $s2 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultDomainName")
        If Not @error Then 
            RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultDomainName")
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultDomainName", "REG_SZ",$s2)
        EndIf
        $s3 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultUserName")
        If Not @error Then 
            RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultUserName")
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName", "REG_SZ", $s3)
        EndIf
        $s4 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultPassword")
        If Not @error Then 
            RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultPassword")
            RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultPassword", "REG_SZ", $s4)
        EndIf
        ; Remove/Reset the registrykey to start this program again after reboot
        RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "AutoItInstaller")
    EndIf
EndFunc   ;==>SetAutoLogon

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

Share this post


Link to post
Share on other sites

Edit: Actually trancexx did say "And using command line options (switches)." I guess he caught that too.

I guess she caught that too. Have a look at her profile :idea:

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Shutdown(2)

_RunOnce()

Func _RunOnce()

; Add 2nd part to installation.

Local $key = 'HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce'

RegWrite($key, '', 'Reg_sz', '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /postrun')

EndFunc

I have used this code to reboot but the issue is it starts the script from the begining but i want to resume from where the script left.

How to do that?

Please help.

Thanks.

Share this post


Link to post
Share on other sites

These are functions I am using for that

Global $Title, Global $key="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\"
NoAutoLogon() ; 
;
; $Title = "Step 3: Build Active Directory"
; Do what you want
;
SetAutoLogon()
RestartThisScriptAfterReeboot()
Reboot()
Exit


Func SetAutoLogon() ;Setting up Autologon @LogonDomain 
RegWrite( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ,"DefaultDomainName" ,"REG_SZ", @LogonDomain) 
RegWrite( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ,"DefaultUserName" ,"REG_SZ", "administrator") 
RegWrite( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ,"DefaultPassword" ,"REG_SZ", "password") 
RegWrite( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ,"AutoAdminLogon" ,"REG_SZ", "1") 
EndFunc

Func NoAutoLogon() ;Remove Autologon 
RegDelete( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ,"DefaultDomainName") 
RegDelete( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ,"DefaultUserName") 
RegDelete( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ,"DefaultPassword") 
RegDelete( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ,"AutoAdminLogon" ) 
EndFunc

Func RestartThisScriptAfterReeboot()
RegWrite($KEY,"Title","REG_SZ",$Title)
RegWrite($KEY&"15","","REG_SZ",@ScriptName)
RegWrite($KEY&"15","1","REG_SZ",@ScriptFullPath)
EndFunc

Func Reboot()
  $Res=1
  $res=MsgBox(17,$Title,"Reboot in 10 sec ...",10)
  If $Res=2 then
   Exit
  Else
   Shutdown ( 6 )
   Sleep(20000)
  EndIf
EndFunc

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I do need to login automatically i just want that where the script left for shutdown

it should start executing from the place it left i.e. resume but your script is restarting after reboot.

Edited by sakshi

Share this post


Link to post
Share on other sites

I do not need to login automatically i just want that where the script left for shutdown

it should start executing from the place it left i.e. resume but your script is restarting after reboot.

You mean something like Commander Data after the service or maybe Seven of Nine after her regeneration cycle?

Is that it?

Only... that's happening in some imaginary future.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

No what i want is something like what happens when we install windows in our Pc.

It does some task and then in between it asks for reboot and when we do so it starts further course of action.

same is the case with me .

Please help.

Thanks.

Share this post


Link to post
Share on other sites

You can't continue from where it's left. That's impossible.

Every answer in this thread is telling you that.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Fecking nice code, Jos.

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