Jump to content
Sign in to follow this  
Yogesh

Create a Auto-shutdown script.

Recommended Posts

Yogesh

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 ?

Share this post


Link to post
Share on other sites
fctd

This will work.

uncomment the shutdown comment when testing is done. Else the computer will restart every time. :)

succes!

; 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 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]

Share this post


Link to post
Share on other sites
Yogesh

This will work.

uncomment the shutdown comment when testing is done. Else the computer will restart every time. :)

succes!

; 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

Share this post


Link to post
Share on other sites
fctd

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]

Share this post


Link to post
Share on other sites
iHonda

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 by iHonda

A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites
fctd

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]

Share this post


Link to post
Share on other sites
Yogesh

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!

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  

×