Yogesh Posted January 11, 2009 Share Posted January 11, 2009 Hi there...I'm relatively new here... I am making a script ....I am not able to give a command like ... Shutdown the PC and close an application whenever the time is 7.30...My script takes really long time to complete the given job usually hours ...so I cant use the If else ladder....any suggestions ? Link to comment Share on other sites More sharing options...
fctd Posted January 11, 2009 Share Posted January 11, 2009 (edited) This will work. uncomment the shutdown comment when testing is done. Else the computer will restart every time. succes! expandcollapse popup; Auto Restart ; AutoIt Version: 3.0 ; Language: English ; Platform: Win XP Embedded ; Author: fctd ; Revision: 1.0 ; Script Function: Automatic shutdown of a PC at 03:00:00 hours ; indude library #include <GuiConstantsEx.au3> #include <Date.au3> #include <WindowsConstants.au3> ; ; define global variables Global $iMemo Global $nRestartHour = 3 ; message $answer = MsgBox(0, "Forced shutdown", "This script will automaticly shutdown the pc at 03:00:00 hours.",15) ; Run Functions Display() Main() ShuttingDown() ; Main program loop Func Main() Do ; wait until it's time to restart the PC if (@HOUR = $nRestartHour And @MIN = 0 AND @SEC = 0) Then ExitLoop EndIf ; check if newcs is succesfully restarted, else restart newcs. Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ; Shut down function Func ShuttingDown() ;Shutdown(5) ;Force a shutdown MsgBox(0, "Automatic program", "!! Shutting down !!",15) EndFunc ; Show display Func Display() Local $hGUI, $tCur, $tNew ; Create GUI (Graphical User Interfaces) $hGUI = GUICreate("Auto Restart", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Get current system time $tCur = _Date_Time_GetLocalTime() MemoWrite("Program started at: " & _Date_Time_SystemTimeToDateTimeStr($tCur)) MemoWrite("") MemoWrite("This PC will shutdown at 03:00:00 hours or when this message is closed") EndFunc ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF,1) EndFunc Sorry, changed it from restarting to shutting down. Edited January 11, 2009 by fctd [list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font] Link to comment Share on other sites More sharing options...
Yogesh Posted January 11, 2009 Author Share Posted January 11, 2009 This will work. uncomment the shutdown comment when testing is done. Else the computer will restart every time. succes! expandcollapse popup; Auto Restart ; AutoIt Version: 3.0 ; Language: English ; Platform: Win XP Embedded ; Author: fctd ; Revision: 1.0 ; Script Function: Automatic shutdown of a PC at 03:00:00 hours ; indude library #include <GuiConstantsEx.au3> #include <Date.au3> #include <WindowsConstants.au3> ; ; define global variables Global $iMemo Global $nRestartHour = 3 ; message $answer = MsgBox(0, "Forced shutdown", "This script will automaticly shutdown the pc at 03:00:00 hours.",15) ; Run Functions Display() Main() ShuttingDown() ; Main program loop Func Main() Do ; wait until it's time to restart the PC if (@HOUR = $nRestartHour And @MIN = 0 AND @SEC = 0) Then ExitLoop EndIf ; check if newcs is succesfully restarted, else restart newcs. Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ; Shut down function Func ShuttingDown() ;Shutdown(5) ;Force a shutdown MsgBox(0, "Automatic program", "!! Shutting down !!",15) EndFunc ; Show display Func Display() Local $hGUI, $tCur, $tNew ; Create GUI (Graphical User Interfaces) $hGUI = GUICreate("Auto Restart", 400, 300) $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Get current system time $tCur = _Date_Time_GetLocalTime() MemoWrite("Program started at: " & _Date_Time_SystemTimeToDateTimeStr($tCur)) MemoWrite("") MemoWrite("This PC will shutdown at 03:00:00 hours or when this message is closed") EndFunc ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF,1) EndFunc Sorry, changed it from restarting to shutting down.Welll....a...Thats Nice....But..Where should I paste these statements in my script....Frankly speaking I didnt understand a word from the above command line....I have never used the GUI interface of AutoIt till now...I just use the plain old Autoit..with no header files n all Link to comment Share on other sites More sharing options...
fctd Posted January 11, 2009 Share Posted January 11, 2009 Did you run the script? The GUI is not nessesary Please post youre script? [list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font] Link to comment Share on other sites More sharing options...
iHonda Posted January 11, 2009 Share Posted January 11, 2009 (edited) er.. i got a newbie question... but where does memowrite come from?? i cant find it in the help file *edit* didnt scroll all the way down in the codebox *feels like a dork* Edited January 11, 2009 by iHonda A great place to start Autoit 1-2-3 Link to comment Share on other sites More sharing options...
fctd Posted January 11, 2009 Share Posted January 11, 2009 Don't worry, Be happy [list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font] Link to comment Share on other sites More sharing options...
Yogesh Posted January 12, 2009 Author Share Posted January 12, 2009 Well I read the whole script....But I actually found an easy alternate way....I ran a parallel script that shuts down the PC @ 7.30 Thanx for The help anyway! 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