AmphetaMarinE Posted September 14, 2007 Share Posted September 14, 2007 (edited) Hi, I'm writing a basic script to restart a PC after 30 secs. The idea behind it is to automate the rebooting of a PC, in the workshop at my workplace. (Many repairs have intermittent boot problems, and it is a waste of time having a technician keep checking and manually rebooting the PC) The script works fine, except that on slower PC's, the 30sec timer is pretty much finished before the login process is complete. Does anyone know of a way to have the script wait until the PC is active and responsive, short of changing to a longer timeout? (The bootup process is quite different across different PC's so a longer wait time would not be my first choice obviously.) I have tried searching, but cant find any relevant results in the forum, and the help txts only give me ideas for things like processwait etc... Problem there is I must wait for a process to close, meaning I can't do say a, ProcessWait ('explorer.exe') or anything like that, as the script will remain paused indefinately there.... My code so far: expandcollapse popup#include <GUIConstants.au3> ; Set the script to autorun on next boot. RegWrite('HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce', 'Restart Timer', 'REG_SZ', @ScriptDir & '\Restart Timer.exe') $MainWindow = GUICreate("ACW Restart Timer", 218, 129, 502, 275) $CancelButton = GUICtrlCreateButton("Cancel", 72, 96, 73, 25, 0) $TimerText = GUICtrlCreateLabel("Restart in:", 56, 16, 52, 17) $Timer = GUICtrlCreateLabel("0:30", 112, 16, 38, 17) $TextLabel1 = GUICtrlCreateLabel("Press cancel to remove autorun", 32, 56, 154, 17) $TextLabel2 = GUICtrlCreateLabel("entries and exit the restart timer.", 32, 72, 153, 17) GUISetState(@SW_SHOW) $time = TimerInit() WinWaitActive('ACW Restart Timer') While 1 $nMsg = GUIGetMsg() Switch $nMsg ;If Cancel Button Pressed, or the dialogue is closed, remove the autorun entry and exit the script Case $GUI_EVENT_CLOSE RegDelete('HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce', 'Restart Timer') ; Create a logfile to allow for monitoring of total number of restarts $logfile = FileOpen('Restart Log.txt', 1) ; Check if file opened for writing OK If $logfile = -1 Then MsgBox(0, 'Error', 'Unable to open file.') Exit EndIf ; Write the time and date of the cancellation to the logfile FileWrite($logfile, '!!Restart aborted on ' & @MDAY & '/' & @MON & '/' & @YEAR & ' at ' & @HOUR & ':' & @MIN & ':' & @SEC & '!!' & @CRLF) ; Close the logfile for writing FileClose($logfile) Exit ;If Cancel Button Pressed, or the dialogue is closed, remove the autorun entry and exit the script Case $CancelButton RegDelete('HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce', 'Restart Timer') ; Create a logfile to allow for monitoring of total number of restarts $logfile = FileOpen('Restart Log.txt', 1) ; Check if file opened for writing OK If $logfile = -1 Then MsgBox(0, 'Error', 'Unable to open file.') Exit EndIf ; Write the time and date of the cancellation to the logfile FileWrite($logfile, 'Computer Name: ' & @ComputerName & ' - !!Restart aborted on ' & @MDAY & '/' & @MON & '/' & @YEAR & ' at ' & @HOUR & ':' & @MIN & ':' & @SEC & '!!' & @CRLF) ; Close the logfile for writing FileClose($logfile) Exit EndSwitch ;Set the initial timer length. (Alter the middle value in $new to change the amount of seconds) $new = (1 * 30 * 1000) - TimerDiff($time) $seconds = Round($new / 1000) $newMin = Floor($seconds / 60) $newSec = Mod($seconds, 60) If $newSec < 10 Then $newSec = "0" & $newSec If ($newMin > 0 Or Number($newSec) > 0) Then GUICtrlSetData($Timer, $newMin & ":" & $newSec) Else GUICtrlSetData($Timer, "0:00") ; Create a logfile to allow for monitoring of total number of restarts $logfile = FileOpen('Restart Log.txt', 1) ; Check if file opened for writing OK If $logfile = -1 Then MsgBox(0, 'Error', 'Unable to open file.') Exit EndIf ; Write the time and date of each restart to the logfile FileWrite($logfile, 'Computer Name: ' & @ComputerName & ' - Restarted on ' & @MDAY & '/' & @MON & '/' & @YEAR & ' at ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF) ; Close the logfile for writing FileClose($logfile) ; Perform a forced restart of the PC Shutdown(6) Exit EndIf WEnd ; Finished! Thanks for any help AmphetaMarinE Edited September 14, 2007 by AmphetaMarinE Link to comment Share on other sites More sharing options...
BillLuvsU Posted September 14, 2007 Share Posted September 14, 2007 Try checking the processor usage. Just wait to it gets down to 5% or less to start the timer, or somthing like that. Hope that helps! [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw Link to comment Share on other sites More sharing options...
AmphetaMarinE Posted September 14, 2007 Author Share Posted September 14, 2007 Hrmm... a tough one, I have no idea where to start with the check, as some PC's will have dual core cpu's... Made a test, and it works fine on a single core CPU, but not on a dual core.... Currently looking at a UDF called CompInfo.au3.... Will report back after playing with that. Thanks heaps for the idea fear1313 Link to comment Share on other sites More sharing options...
BillLuvsU Posted September 14, 2007 Share Posted September 14, 2007 (edited) No Problem, Thats what 'm here for ;P As for the dual core issue, I would just combine the two percents into one number. make it easier. but then again that may not be possible since I don't have and have never scripted on a dual core machine. Edited September 14, 2007 by fear1313 [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw Link to comment Share on other sites More sharing options...
smoochy Posted May 14, 2008 Share Posted May 14, 2008 Sry for digging up this thread but i head to deal with this problem some days ago. I found a very good solution in another forum (don´t remember which), but here is, how you can do it easily:While 1 If Ping($Computername) > 0 Then If RunWait("Portqry.exe -n " & $Computername & " -p tcp -e 3389 -q") = 0 Then; checks, if Terminal Services Service is started, which means computer is fully booted up ;do what you want ExitLoop EndIf EndIf Sleep(5000) WEndPortqry.exe is a fine little tool, which you can get @Microsoft.PS: This AutoIt Code Button doesn´t work (Firefox 2.0.0.14 @ Vista Ultimate 64bit) Link to comment Share on other sites More sharing options...
billybobjoebob Posted August 25, 2008 Share Posted August 25, 2008 I am a complete noob to autoit and have tried the 1-2-3 thing, but it is sort of confusing to operate. Anyway when you find out how to make the program turn off your computer and when it reboots, to turn it off again +loop please send it to me. I would love to know how to do this. Link to comment Share on other sites More sharing options...
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