Jump to content

Create a Auto-shutdown script.


Yogesh
 Share

Recommended Posts

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

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]

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...