sakshi Posted May 13, 2010 Posted May 13, 2010 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.
water Posted May 13, 2010 Posted May 13, 2010 (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 May 13, 2010 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
trancexx Posted May 13, 2010 Posted May 13, 2010 (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 May 13, 2010 by trancexx ♡♡♡ . eMyvnE
ShawnW Posted May 13, 2010 Posted May 13, 2010 (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 May 13, 2010 by ShawnW
damon Posted May 13, 2010 Posted May 13, 2010 (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 May 13, 2010 by damon It always amazes me how one little thing can cause so much havoc
wolf9228 Posted May 13, 2010 Posted May 13, 2010 (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 May 13, 2010 by wolf9228 صرح السماء كان هنا
Developers Jos Posted May 13, 2010 Developers Posted May 13, 2010 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. expandcollapse popup; 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 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
water Posted May 14, 2010 Posted May 14, 2010 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 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
sakshi Posted May 19, 2010 Author Posted May 19, 2010 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.
FranckGr Posted May 19, 2010 Posted May 19, 2010 These are functions I am using for that expandcollapse popupGlobal $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
sakshi Posted May 19, 2010 Author Posted May 19, 2010 (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 May 19, 2010 by sakshi
trancexx Posted May 19, 2010 Posted May 19, 2010 I do not need to login automatically i just want that where the script left for shutdownit 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
sakshi Posted May 19, 2010 Author Posted May 19, 2010 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.
trancexx Posted May 19, 2010 Posted May 19, 2010 You can't continue from where it's left. That's impossible.Every answer in this thread is telling you that. ♡♡♡ . eMyvnE
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now