Jump to content

Help needed to create script to provide user messagebox to defer restart and autostart after 1 hour


Recommended Posts

Hi Folks.. Am new to AutoIt scripting. I need help with following scenario.

 Am trying to create a script to reboot a machine where user should be able to able to have a option with message box buttons restart now or restart later. If user selects restart later it should autostart and prompt user again after 1 hour  and if he select to restart later again. 3rd time after 1 hour it should restart with display message saying its gonna reboot. Thanks in advance.

 

 

Link to comment
Share on other sites

Hey sreeharsha, that's kind of a bold move if you're new to the language, but,

if you are willing to learn, we can push you in the right direction.

First of all, you need some code, as Earthshine mentioned.

In that code you will need to put functions, timers, messageboxes.

Go on and research a bit on that, come back with the doubts you got.

BTW ExtMsgBox would be perfect to create those message boxes you want.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

sreeharsha,

This link was found using the "Search" dialog in the upper right corner.

kylomas

P.S. Welcome to the forum.  Help is here commensurate with the effort you show!

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Hi All.. I was able to make use of this perfectly. But I need this function to autostart 2 more times in 60 minutes interval and exit.

 

Thanks

 

 

#NoTrayIcon
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Timers.au3>
#include <Date.au3>
#include <ProgressConstants.au3>

FileInstall("Enforcer.ini", @ScriptDir & "\Enforcer.ini")

Global  $Processes = IniRead(@ScriptDir & "\Enforcer.ini", "Parameters", "Process", "") ; Reads from config file, a list of process.
$Cancel_If_Running = StringSplit( $Processes, "|") ; Takes the $Processes value into an Array

If IsArray ($Cancel_If_Running) Then
    For $i = 1 to $Cancel_If_Running[0]
        If ProcessExists ($Cancel_If_Running[$i]) Then Exit ; If specified process(es) is / are running the script will exit.
    Next
EndIf

Global $iCountdown = IniRead(@ScriptDir & "\Enforcer.ini", "Parameters", "DelayTime", 10) ; Sets the time-out in seconds
Global $Prompt = "To help improve performance, it is recommended that this workstation is restarted." & @CRLF & "Windows will restart your computer automatically in "
Global $iTotal_Time = $iCountdown ; Copies the starting time to another variable.

$Form1 = GUICreate("Restart Required", 415, 145, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_WINDOWEDGE) ; Creates GUI Window
$Progress = GUICtrlCreateProgress(10, 65, 395, 15, $PBS_SMOOTH) ; Creates Progress Bar
GUICtrlSetColor($Progress, 0xff0000) ; Sets Progress Bar Colour
$RestartNow = GUICtrlCreateButton("Restart Now", 235, 112, 80, 23, 0) ; Creates Restart Now Button
$RestartLater = GUICtrlCreateButton("Restart Later", 325, 112, 80, 23, 0) ; Creates Restart Latter Button
$Label1 = GUICtrlCreateLabel($Prompt & _SecsToTime($iCountdown) & " minutes.", 10, 10, 405, 55)
$Label2 = GUICtrlCreateLabel("Do you want to restart your computer now?", 10, 90, 405, 20)
GUISetState(@SW_SHOW)

_Timer_SetTimer($Form1, 1000, '_Countdown')
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $RestartNow
            _Restart()
        Case $RestartLater
            Exit
    EndSwitch
WEnd

Func _Countdown($hWnd, $iMsg, $iIDTimer, $dwTime)
    $iCountdown -= 1
    $percent_value = Floor(($iCountdown / $iTotal_Time) * 100)
    $percent_value = 100 - $percent_value
    If $iCountdown > 0 Then
        GUICtrlSetData($Label1, $Prompt & _SecsToTime($iCountdown) & " minutes.")
        GUICtrlSetData($Progress, $percent_value)
    ElseIf $iCountdown = 0 Then
        GUICtrlSetData($Label1, $Prompt & _SecsToTime($iCountdown) & " minutes.")
        GUICtrlSetData($Progress, $percent_value)
        _Timer_KillTimer($hWnd, $iIDTimer)
        ControlClick($Form1, '', $RestartNow) ; Default action when Countdown equals 0
    EndIf
EndFunc  ;==>_Countdown

Func _SecsToTime($iSecs)
    Local $iHours, $iMins, $iSec_s
    _TicksToTime($iSecs*1000,$iHours,$iMins,$iSec_s)
    Return StringFormat("%02i:%02i:%02i",$iHours,$iMins, $iSec_s)
EndFunc

Func _Restart()
    Shutdown(6)  ;Force a reboot
    Exit
EndFunc


enforcer.ini

[parameters]

DelayTime=5400

Link to comment
Share on other sites

35 minutes ago, sreeharsha said:

 I need this function to autostart 2 more times in 60 minutes interval and exit.

Code quotes next time please.

 

As for the code, there are a couple of ways to "autostart" it. But I would just do a simple condition check and increment a variable up to the amount of times you want it to restart. You have most of the work done improve on it.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Can anyone provide me with an example to run my reboot script after 30 mins If user wants to defer reboot. Actually we have a scenario where we need to apply HKCU reg hacks and provide user ability to defer reboot twice and force restart 3rd time. Thanks in advance :)

Link to comment
Share on other sites

Actually below is what exactly am looking for. Instead of repeating every time I want this script to repeat reboot only for 2 times and force reboot for 3rd time not giving an option to defer reboot.

 

 

#include <Constants.au3>
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; Hide the tray icon so users don't just abort your script
Opt("TrayIconHide", 1)      ;0=show, 1=hide tray icon

$Timeout = 15 ; in minutes
$code = $SD_SHUTDOWN
$Elapse= 60000 ; 60 seconds
while 1
    ;Beep()
    $GUI = GUICreate ("shuting Down the Computer", 400, 200, -1, -1, -1, $WS_EX_TOPMOST)
    $progress=GUICtrlCreateProgress (110, 80, 200,30)
    $cancel=GUICtrlCreateButton ("Give me another " & $Timeout & " minutes",130,130, 150)
    $state=GUICtrlCreateLabel ("Windows is shutting down...",50,50, 150)
    GuiCtrlSetState (-1, $GUI_HIDE)
    $state1=GUICtrlCreateLabel ("Shuddown in " & int($elapse / 1000) & " seconds",50,50, 150) ; show them the seconds with the progress bar
    GuiSetState()
    $start = TimerInit()
    Do
        $msg=GuiGetMsg()
        $diff=TimerDiff($start)
        if  $diff>=$elapse then
            GuiCtrlSetState($cancel, $GUI_HIDE)
            GuiCtrlSetState($state1, $GUI_HIDE)
            GuiCtrlSetState($state, $GUI_SHOW)
            Shutdown($code)
         Exit
        EndIf
        Sleep (100)
        GuiCtrlSetData($progress, $diff*100/$elapse)
        GUICtrlSetData($state1, "Shuddown in " & String(int(($elapse - $diff)/1000)) & " seconds")
    Until $msg=$GUI_EVENT_CLOSE OR $msg= $cancel
    GUIDelete($gui) ; clear the gui out of memory while we don't need it
    Sleep($Timeout * 60000) ; wait $timeout minutes, then do it again
WEnd
Link to comment
Share on other sites

so add a new variable to track how many times you have been through the process. a switch statement can them be used to know when to actually reboot. write it up and post the code back here if not working for more assistance.

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

2 hours ago, sreeharsha said:

Thankyou kylomas for provided link. While am doing my test am getting an error saying undeclared global variables.

Need to add

#include 'AutoItConstants.au3'

Remarks

The shutdown code is a combination of the following values:
    $SD_LOGOFF (0) = Logoff
    $SD_SHUTDOWN (1) = Shutdown
    $SD_REBOOT (2) = Reboot
    $SD_FORCE (4) = Force
    $SD_POWERDOWN (8) = Power down
    $SD_FORCEHUNG (16) = Force if hung
    $SD_STANDBY (32) = Standby
    $SD_HIBERNATE (64) = Hibernate

Constants are defined in AutoItConstants.au3.

Because you used the constant, you need the include that defines said constant. Or you put the number.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Hi Earthshine,

                          Can you please provide me a sample script to track down how many times user went through process and switch statement to reboot. It might also help me if you can you can refer anykind of script.

As am a newbie to autoit am still in learning process. Thanks in advance

Link to comment
Share on other sites

To track down how many times, use a variable, and keep incrementing it's value each time the user skips the reboot.

The "switch statement" can be a msgbox with the apropriate flag for ok - cancel, or yes - no, or whatever, see help file.

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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...