Sign in to follow this  
Followers 0
azure

script delay wrapper / snooze / run script in x minutes

14 posts in this topic

Ok. Here's what I'm trying to accomplish.

I'm trying to create a script that will take parameters that will call something else. We have a bunch of install scripts here and would love to push them out remotely, but our management isn't keen on things running while users are in the middle of things. I'd like to create a snooze wrapper.. sort of like the windows update "reboot now or 4 hours from now" dialog box you've seen.

snooze.exe exeToCall

type thing.

This is what I've got so far... but I want to be able to account for calling things with parameters.. and be able to map a drive if needed so that a "cscript install.vbs" doesn't fail from a UNC.

If Not IsDeclared("iMsgBoxAnswer") Then Global $iMsgBoxAnswer
If Not IsDeclared("scriptittle") Then Global $scripttitle
If Not IsDeclared("scriptrun") Then Global $scriptrun

Select
    Case $cmdLine[0] = 2
        $scripttitle = $CmdLine[1]
        $scriptrun = $CmdLine[2]
        $comspec = 0
    Case $cmdLine[0] = 3
        $scripttitle = $CmdLine[1]
        $scriptrun = $CmdLine[2]
        $comspec = $CmdLine[3]
    Case Else
        MsgBox(0,"Error Running Snooze","Command Syntax:"&@CR&@TAB&"snooze.exe scriptName scriptPath"&@CR&@TAB&"Example:"&@CR&@TAB&"snooze.exe Notepad notepad.exe")
        Exit(-1)
EndSelect

Do
$iMsgBoxAnswer = MsgBox(4,"Run Now?","Would you like to launch "&$scripttitle&" now?" & @CR & @CR & "- Clicking ''YES'' opens the file immediately." & @CR & "- Clicking ''NO'' brings up box to delay the launch of this program.",120)
Select
    Case $iMsgBoxAnswer = -1 ;Timeout
        Runme($comspec)
    Case $iMsgBoxAnswer = 6 ;Yes
        RunMe($comspec)
    Case $iMsgBoxAnswer = 7 ;No
      
            Do
                $input = InputBox($scripttitle & " reminder ...", "Snooze for how many minutes?" & @CR & "- Max Of 240 minutes!", 15)
            Until $input < 241
            $time = $input*1000*60
            Sleep($time)
        
        #NoTrayIcon     ; AutoIt's icon doesn't show in systray
      
EndSelect
Until $iMsgBoxAnswer <> 7
Exit(0)

Func RunMe($comspec = 0)
    ;ShellExecuteWait($scriptrun,"","","",@SW_MINIMIZE)
    $workingdirA = StringSplit($scriptrun,"\")
    $workingdir = ""
    If $workingdirA[0] > 1 Then
        For $i = 1 To $workingdirA[0]-1
            $workingdir = $workingdir & $workingdirA[$i] & "\"
        Next
    EndIf
    ;MsgBox(0,"","RunWait("&$scriptrun&","&$workingdir&",@SW_MINIMIZE)")
    If $comspec = 0 Then
        RunWait($scriptrun,$workingdir,@SW_MINIMIZE)
    Else
        RunWait(@COMSPEC & " /c " & $scriptrun,$workingdir,@SW_MINIMIZE)
    EndIf
EndFunc

It would also be nice to fancy this up some.. with, say, a countdown where if there isn't any user input, it just runs the script.

Does anyone have something like this already done, or can point me to an example? Any help will be greatly appreciated.

Share this post


Link to post
Share on other sites



I'm not sure if you wanted it this way but it repeats the same startup menu if you click on "no" after the time. It is a good project though maybe I could use this in a project for shutdown that I have been implementing


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

I'm not sure if you wanted it this way but it repeats the same startup menu if you click on "no" after the time. It is a good project though maybe I could use this in a project for shutdown that I have been implementing

Well.. This works.. sort of, I just think it's ugly, and I can't imagine someoen else hasn't thought of doing this or has done something like this already.

in this particular script, if you click NO, it opens an INPUT box that lets you type in a number of minutes to delay the script.. after that many minutes, it asks you if you want to run the script or delay it some more.

Objectives are, being able to pass command line parameters, being able to map a drive / working directory so that a batch file that points to "cscript install.vbs" would work using a UNC, and making it prettier with a countdown, maybe something GDI? (I saw a nice GDI ping script that used a loop with a pie graph as a sort of progress bar).

Share this post


Link to post
Share on other sites

It should have a calendar/timer to more incorporate it into windows function those increasing the overall use of this project. If you use a gui/console switching between them would be perfered as it will keep memory usage down. As for the countdown I'll incorporate it for you in my next message after messing with that code then a GDI


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

Do
                $input = InputBox($scripttitle & " reminder ...", "Snooze for how many minutes?" & @CR & "- Max Of 240 minutes!", 15)
            Until $input < 241
            $time = ($input*600)
            
            ProgressOn("Progress Meter", "Increments every second", "0 percent")
            For $i = 1 to 100
                sleep($time)
                ProgressSet( $i, $i & " percent")
            Next
            ProgressSet(100 , "Done", "Complete")
            ProgressOff()


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

@Everybody

:) What's that ? perhaps im out but ...

_DateDiff ; TimerInit ; TimerDiff isnt better for this ?

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Do
                $input = InputBox($scripttitle & " reminder ...", "Snooze for how many minutes?" & @CR & "- Max Of 240 minutes!", 15)
            Until $input < 241
            $time = ($input*600)
            
            ProgressOn("Progress Meter", "Increments every second", "0 percent")
            For $i = 1 to 100
                sleep($time)
                ProgressSet( $i, $i & " percent")
            Next
            ProgressSet(100 , "Done", "Complete")
            ProgressOff()
Well.. I know how to do a progress bar like that.. but I don't want to disturb the user that much. I meant, more along the lines of when the message box "DO YOU WANT TO RUN THIS NOW?" first comes up.. have that window have some sort of countdown until "YES" is automatically chosen FOR you..

And if you snooze it, having it occiaisionally popup a traytip or something that says "You've got 10 minutes left" or whatever.

@FireFox,

Probably... I got a base of the code I posted originally from an example in another post here on this forum.

Guess I'm just fishing for, "has anyone done this before?"

Share this post


Link to post
Share on other sites

@azure

$init = TimerInit()

While 1
;do your script as you like :)
Sleep(250)
$diff = TimerDiff($init)
; 1000ms = 1sec = ms/1000
; 60 = 1 min (10min = 60*10)
If $diff/1000 >= 600 then
Msgbox(64, 'Timer', 'Alert ! its the time to wake up :)')
EndIf
WEnd

Not tested.

Cheers, FireFox.

EndIf


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Here you go tested it as much as I could and got rid of most of the bugs, I decided to work on this after firemen's meeting tonight that lasted till 10:00. Here it is:

#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

If Not IsDeclared("dTimer") Then Global $dTimer

If $cmdLine[0] > 0 Then
    If Not IsDeclared("sScriptRun") Then Global $sScriptRun = $cmdLine[1]
    If Not IsDeclared("sScriptComspec") Then Global $sScriptComspec = 0
    If $cmdLine[0] = 2 Then
        $sScriptComspec = $cmdLine[2]
    EndIf
Else
    MsgBox(0, "Error Running Snooze Wrapper", "Command Syntax:" & @CR & @TAB & @ScriptName & " <script path> [<comspec>]" & @CR & @TAB & @ScriptName & " notepad.exe")
    Exit (-1)
EndIf

$hMainForm = GUICreate("Snooze Wrapper", 250, 270)
$hLabelInfo = GUICtrlCreateLabel("Would you like to launch it now?", 16, 16, 219, 54)
$hButtonYes = GUICtrlCreateButton("&Yes", 16, 37, 75, 25, 0)
GUICtrlSetTip(-1, "Clicking 'Yes' opens the file.")
$hButtonNo = GUICtrlCreateButton("&No", 101, 37, 75, 25, 0)
GUICtrlSetTip(-1, "Clicking 'No' bring up the box to delay the launch of " & $sScriptRun)
$hEditInfo = GUICtrlCreateEdit("Used for data and a place to log", 16, 68, 218, 166)
GUICtrlSetData(-1, "")
$hMainStatus = _GUICtrlStatusBar_Create($hMainForm)

GUISetState(@SW_SHOW, $hMainForm)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit (1)
        Case $hButtonYes
            RunMe($sScriptComspec)
        Case $hButtonNo
            $hChildForm = GUICreate("Reminder....", 192, 83, 517, 342)
            $hChildLabelInfo = GUICtrlCreateLabel("How long do you want to wait for?", 16, 8, 176, 17)
            $hChildButtonYes = GUICtrlCreateButton("&Yes", 16, 37, 75, 25, 0)
            GUICtrlSetState(-1, $GUI_HIDE)
            $hChildButtonNo = GUICtrlCreateButton("&No", 101, 37, 75, 25, 0)
            GUICtrlSetState(-1, $GUI_HIDE)
            $hChildInputInfo = GUICtrlCreateInput("10", 16, 24, 151, 21)
            $hChildButtonDone = GUICtrlCreateButton("&Done", 56, 48, 75, 25, 0)

            GUISetState(@SW_DISABLE, $hMainForm)
            GUISetState(@SW_SHOW, $hChildForm)
            $tTimerInit = TimerInit()
            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $hChildButtonDone
                        _DocumentCheck()
                    Case $hChildButtonYes
                        ExitLoop
                    Case $hChildButtonNo
                        GUISetState(@SW_HIDE, $hChildForm)
                        GUICtrlSetData($hChildLabelInfo, "Snooze for how many minutes?")
                        GUICtrlSetState($hChildInputInfo, $GUI_SHOW)
                        GUICtrlSetState($hChildButtonDone, $GUI_SHOW)
                        GUICtrlSetState($hChildButtonYes, $GUI_HIDE)
                        GUICtrlSetState($hChildButtonNo, $GUI_HIDE)
                        GUISetState(@SW_SHOW, $hChildForm)
                        $tTimerInit = TimerInit()
                EndSwitch

                $tTimerDifference = TimerDiff($tTimerInit)
                If $tTimerDifference > 3000 Then
                    If GUICtrlGetState($hChildButtonDone) == 80 Then
                        _DocumentCheck()
                    Else
                        ExitLoop
                    EndIf
                EndIf

            WEnd

            RunMe($sScriptComspec)
    EndSwitch
WEnd

Func _DocumentCheck()
    If StringIsDigit(GUICtrlRead($hChildInputInfo)) Then
        $dTimer = GUICtrlRead($hChildInputInfo) * 60

        GUISetState(@SW_HIDE, $hChildForm)
        Local $aParts[1] = [175]

        _GUICtrlStatusBar_SetParts($hMainStatus, $aParts)
        $pProgress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_SMOOTH)
        $hProgress = GUICtrlGetHandle($pProgress)
        _GUICtrlStatusBar_EmbedControl($hMainStatus, 0, $hProgress)

        GUISetState(@SW_ENABLE, $hMainForm)
        GUICtrlSetState($hButtonNo, $GUI_DISABLE)
        For $i = 0 To 100
            Sleep($dTimer)
            GUICtrlSetData($pProgress, $i)
        Next

        GUICtrlSetData($hChildLabelInfo, "Do you want to run this now?")
        GUICtrlSetState($hChildInputInfo, $GUI_HIDE)
        GUICtrlSetState($hChildButtonDone, $GUI_HIDE)
        GUICtrlSetState($hChildButtonYes, $GUI_SHOW)
        GUICtrlSetState($hChildButtonNo, $GUI_SHOW)
        GUISetState(@SW_DISABLE, $hMainForm)
        GUISetState(@SW_SHOW, $hChildForm)
    EndIf

    $tTimerInit = TimerInit()
EndFunc   ;==>_DocumentCheck

Func RunMe($sComspec = 0)
    GUISetState(@SW_HIDE, $hMainForm)

    $aWorkingDir = StringSplit($sScriptRun, "\")
    $sWorkingDir = ""
    If $aWorkingDir[0] > 1 Then
        For $i = 1 To $aWorkingDir[0] - 1
            $sWorkingDir = $sWorkingDir & $aWorkingDir[$i] & "\"
        Next
    EndIf
    If $sComspec = 0 Then
        RunWait($sScriptRun, $sWorkingDir, @SW_MINIMIZE)
    Else
        RunWait(@ComSpec & " /c " & $sScriptRun, $sWorkingDir, @SW_MINIMIZE)
    EndIf
    Exit (1)
EndFunc   ;==>RunMe

Hope you like it

Edited by TerarinK

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

Here you go tested it as much as I could and got rid of most of the bugs, I decided to work on this after firemen's meeting tonight that lasted till 10:00. Here it is:

#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

If Not IsDeclared("dTimer") Then Global $dTimer

If $cmdLine[0] > 0 Then
    If Not IsDeclared("sScriptRun") Then Global $sScriptRun = $cmdLine[1]
    If Not IsDeclared("sScriptComspec") Then Global $sScriptComspec = 0
    If $cmdLine[0] = 2 Then
        $sScriptComspec = $cmdLine[2]
    EndIf
Else
    MsgBox(0, "Error Running Snooze Wrapper", "Command Syntax:" & @CR & @TAB & @ScriptName & " <script path> [<comspec>]" & @CR & @TAB & @ScriptName & " notepad.exe")
    Exit (-1)
EndIf

$hMainForm = GUICreate("Snooze Wrapper", 250, 270)
$hLabelInfo = GUICtrlCreateLabel("Would you like to launch it now?", 16, 16, 219, 54)
$hButtonYes = GUICtrlCreateButton("&Yes", 16, 37, 75, 25, 0)
GUICtrlSetTip(-1, "Clicking 'Yes' opens the file.")
$hButtonNo = GUICtrlCreateButton("&No", 101, 37, 75, 25, 0)
GUICtrlSetTip(-1, "Clicking 'No' bring up the box to delay the launch of " & $sScriptRun)
$hEditInfo = GUICtrlCreateEdit("Used for data and a place to log", 16, 68, 218, 166)
GUICtrlSetData(-1, "")
$hMainStatus = _GUICtrlStatusBar_Create($hMainForm)

GUISetState(@SW_SHOW, $hMainForm)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit (1)
        Case $hButtonYes
            RunMe($sScriptComspec)
        Case $hButtonNo
            $hChildForm = GUICreate("Reminder....", 192, 83, 517, 342)
            $hChildLabelInfo = GUICtrlCreateLabel("How long do you want to wait for?", 16, 8, 176, 17)
            $hChildButtonYes = GUICtrlCreateButton("&Yes", 16, 37, 75, 25, 0)
            GUICtrlSetState(-1, $GUI_HIDE)
            $hChildButtonNo = GUICtrlCreateButton("&No", 101, 37, 75, 25, 0)
            GUICtrlSetState(-1, $GUI_HIDE)
            $hChildInputInfo = GUICtrlCreateInput("10", 16, 24, 151, 21)
            $hChildButtonDone = GUICtrlCreateButton("&Done", 56, 48, 75, 25, 0)

            GUISetState(@SW_DISABLE, $hMainForm)
            GUISetState(@SW_SHOW, $hChildForm)
            $tTimerInit = TimerInit()
            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $hChildButtonDone
                        _DocumentCheck()
                    Case $hChildButtonYes
                        ExitLoop
                    Case $hChildButtonNo
                        GUISetState(@SW_HIDE, $hChildForm)
                        GUICtrlSetData($hChildLabelInfo, "Snooze for how many minutes?")
                        GUICtrlSetState($hChildInputInfo, $GUI_SHOW)
                        GUICtrlSetState($hChildButtonDone, $GUI_SHOW)
                        GUICtrlSetState($hChildButtonYes, $GUI_HIDE)
                        GUICtrlSetState($hChildButtonNo, $GUI_HIDE)
                        GUISetState(@SW_SHOW, $hChildForm)
                        $tTimerInit = TimerInit()
                EndSwitch

                $tTimerDifference = TimerDiff($tTimerInit)
                If $tTimerDifference > 3000 Then
                    If GUICtrlGetState($hChildButtonDone) == 80 Then
                        _DocumentCheck()
                    Else
                        ExitLoop
                    EndIf
                EndIf

            WEnd

            RunMe($sScriptComspec)
    EndSwitch
WEnd

Func _DocumentCheck()
    If StringIsDigit(GUICtrlRead($hChildInputInfo)) Then
        $dTimer = GUICtrlRead($hChildInputInfo) * 60

        GUISetState(@SW_HIDE, $hChildForm)
        Local $aParts[1] = [175]

        _GUICtrlStatusBar_SetParts($hMainStatus, $aParts)
        $pProgress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_SMOOTH)
        $hProgress = GUICtrlGetHandle($pProgress)
        _GUICtrlStatusBar_EmbedControl($hMainStatus, 0, $hProgress)

        GUISetState(@SW_ENABLE, $hMainForm)
        GUICtrlSetState($hButtonNo, $GUI_DISABLE)
        For $i = 0 To 100
            Sleep($dTimer)
            GUICtrlSetData($pProgress, $i)
        Next

        GUICtrlSetData($hChildLabelInfo, "Do you want to run this now?")
        GUICtrlSetState($hChildInputInfo, $GUI_HIDE)
        GUICtrlSetState($hChildButtonDone, $GUI_HIDE)
        GUICtrlSetState($hChildButtonYes, $GUI_SHOW)
        GUICtrlSetState($hChildButtonNo, $GUI_SHOW)
        GUISetState(@SW_DISABLE, $hMainForm)
        GUISetState(@SW_SHOW, $hChildForm)
    EndIf

    $tTimerInit = TimerInit()
EndFunc   ;==>_DocumentCheck

Func RunMe($sComspec = 0)
    GUISetState(@SW_HIDE, $hMainForm)

    $aWorkingDir = StringSplit($sScriptRun, "\")
    $sWorkingDir = ""
    If $aWorkingDir[0] > 1 Then
        For $i = 1 To $aWorkingDir[0] - 1
            $sWorkingDir = $sWorkingDir & $aWorkingDir[$i] & "\"
        Next
    EndIf
    If $sComspec = 0 Then
        RunWait($sScriptRun, $sWorkingDir, @SW_MINIMIZE)
    Else
        RunWait(@ComSpec & " /c " & $sScriptRun, $sWorkingDir, @SW_MINIMIZE)
    EndIf
    Exit (1)
EndFunc   ;==>RunMe

Hope you like it

Doesn't seem to work. I can't click on anything in the window, but when I tab, and hit space to hit a button, the reminder window gets stuck. I like the progress bar in the status bar though. Thanks for the help, I'll see what I can do with some of this code.

Share this post


Link to post
Share on other sites

Bump in hopes someone has done or needed something like this? :)

Share this post


Link to post
Share on other sites

@azure

Can you explain what your problem is now ?

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

@azure

Can you explain what your problem is now ?

Cheers, FireFox.

Well.. it's not a problem, per se. I'm just fishing for anyone that has done something like that. It seems like it would be a relatively common thing.

Share this post


Link to post
Share on other sites

The problem with this code is that for some reason it cancels out the clicking but it is fully functional with the ALT- whatever the keyword is

ALT-y equals Yes

ALT-n equals No

ALT-d equals Done

Maybe I should have made you aware of this, but it happen when I create the second GUI within the parent GUI.


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

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  
Followers 0