CGAnimator Posted April 28, 2009 Share Posted April 28, 2009 hi i want to make a script that runs a certain program when the system is idle but before it run the program it displays a countdown (OK,Cancel) Box here is the countdown gui i made it wont work because of the sleep(1000) at the last few lines i don't know what can solve this problem please help CountDown() Func CountDown() GUICreate("Backburner Server Runner", 300, 120,-1,-1,$WS_DLGFRAME) $Button1 = GUICtrlCreateButton("OK ", 50, 55, 75, 25) $Button2 = GUICtrlCreateButton("Cancel", 198, 55, 75, 25) $Label = GUICtrlCreateLabel("",30, 15, 300, 28) GUISetState() ; will display an dialog box with 2 button ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Run("C:\Program Files\Autodesk\Backburner\server.exe") Case $msg = $Button1 Run("C:\Program Files\Autodesk\Backburner\server.exe") Case $msg = $Button2 ExitLoop EndSelect For $i = 10 to 1 Step -1 GUICtrlSetData($Label,"Backburner Server Will Run in about "& $i& " Secondes") GUICtrlSetData($Button1,"Ok "& $i) Sleep(1000) Next WEnd EndFunc Link to comment Share on other sites More sharing options...
Valuater Posted April 28, 2009 Share Posted April 28, 2009 CountDown() Func CountDown() GUICreate("Backburner Server Runner", 300, 120, -1, -1, $WS_DLGFRAME) $Button1 = GUICtrlCreateButton("OK ", 50, 55, 75, 25) $Button2 = GUICtrlCreateButton("Cancel", 198, 55, 75, 25) $Label = GUICtrlCreateLabel("", 30, 15, 300, 28) GUISetState() ; will display an dialog box with 2 button ; Run the GUI until the dialog is closed $timer = TimerInit() $tHold = 10 GUICtrlSetData($Label, "Backburner Server Will Run in about " & $tHold & " Secondes") GUICtrlSetData($Button1, "Ok " & $tHold) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Run("C:\Program Files\Autodesk\Backburner\server.exe") Case $msg = $Button1 Run("C:\Program Files\Autodesk\Backburner\server.exe") Case $msg = $Button2 ExitLoop EndSelect If TimerDiff($timer) >= 1000 Then $tHold = $tHold - 1 GUICtrlSetData($Label, "Backburner Server Will Run in about " & $tHold & " Secondes") GUICtrlSetData($Button1, "Ok " & $tHold) $timer = TimerInit() If $tHold = 0 Then MsgBox(4096, "", "Do what you want here ", 5) Exit EndIf EndIf WEnd EndFunc ;==>CountDown 8) Link to comment Share on other sites More sharing options...
CGAnimator Posted April 28, 2009 Author Share Posted April 28, 2009 thank you so much it really helps but i still have broplems when the script excute the program the counter freeze when i press ok or cancle the counter freeze also here is the code expandcollapse popup#include <WindowsConstants.au3> #Include <Timers.au3> #include <GUIConstantsEx.au3> While 1 = 1 Sleep( 10 * 1000); 10sec If WinExists("Backburner Server") Then Else Global $iIdleTime = _Timer_GetIdleTime() If $iIdleTime > 20000 Then CountDown() Func CountDown() GUICreate("Backburner Server Runner", 300, 120, -1, -1, $WS_DLGFRAME) $Button1 = GUICtrlCreateButton("OK ", 50, 55, 75, 25) $Button2 = GUICtrlCreateButton("Cancel", 198, 55, 75, 25) $Label = GUICtrlCreateLabel("", 30, 15, 300, 28) GUISetState() $timer = TimerInit() $tHold = 10 GUICtrlSetData($Label, "Backburner Server Will Run in about " & $tHold & " Secondes") GUICtrlSetData($Button1, "Ok " & $tHold) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Run("C:\Program Files\Autodesk\Backburner\server.exe") ExitLoop Case $msg = $Button1 Run("C:\Program Files\Autodesk\Backburner\server.exe") ExitLoop Case $msg = $Button2 ExitLoop EndSelect If TimerDiff($timer) >= 1000 Then $tHold = $tHold - 1 GUICtrlSetData($Label, "Backburner Server Will Run in about " & $tHold & " Secondes") GUICtrlSetData($Button1, "Ok " & $tHold) $timer = TimerInit() If $tHold = 0 Then Run("C:\Program Files\Autodesk\Backburner\server.exe") EndIf EndIf WEnd EndFunc ;==>CountDown Else EndIf EndIf Wend Link to comment Share on other sites More sharing options...
Valuater Posted April 28, 2009 Share Posted April 28, 2009 (edited) Try this... expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Timers.au3> While 1 Sleep(10 * 1000); 10sec If Not WinExists("Backburner Server") Then $iIdleTime = _Timer_GetIdleTime() If $iIdleTime > 20000 Then CountDown() EndIf EndIf WEnd Func CountDown() GUICreate("Backburner Server Runner", 300, 120, -1, -1, $WS_DLGFRAME) $Button1 = GUICtrlCreateButton("OK ", 50, 55, 75, 25) $Button2 = GUICtrlCreateButton("Cancel", 198, 55, 75, 25) $Label = GUICtrlCreateLabel("", 30, 15, 300, 28) GUISetState() $timer = TimerInit() $tHold = 10 GUICtrlSetData($Label, "Backburner Server Will Run in about " & $tHold & " Secondes") GUICtrlSetData($Button1, "Ok " & $tHold) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Run("C:\Program Files\Autodesk\Backburner\server.exe") ExitLoop Case $msg = $Button1 Run("C:\Program Files\Autodesk\Backburner\server.exe") ExitLoop Case $msg = $Button2 ExitLoop EndSelect If TimerDiff($timer) >= 1000 Then $tHold = $tHold - 1 GUICtrlSetData($Label, "Backburner Server Will Run in about " & $tHold & " Secondes") GUICtrlSetData($Button1, "Ok " & $tHold) $timer = TimerInit() If $tHold = 0 Then Run("C:\Program Files\Autodesk\Backburner\server.exe") ExitLoop EndIf EndIf WEnd EndFunc ;==>CountDown 8) Edited April 28, 2009 by Valuater Link to comment Share on other sites More sharing options...
CGAnimator Posted April 28, 2009 Author Share Posted April 28, 2009 your code is too way better than mine and more organized but I still have the same problem Link to comment Share on other sites More sharing options...
Valuater Posted April 28, 2009 Share Posted April 28, 2009 I don't know what the problem is, here i use noted pad at it tested ok expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Timers.au3> Global $File_Name = "Notepad.exe"; "C:\Program Files\Autodesk\Backburner\server.exe" CountDown() ; for testing While 1 Sleep(10 * 1000); 10sec If Not WinExists("Backburner Server") Then $iIdleTime = _Timer_GetIdleTime() If $iIdleTime > 20000 Then CountDown() EndIf EndIf WEnd Func CountDown() $GUI2 = GUICreate("Backburner Server Runner", 300, 120, -1, -1, $WS_DLGFRAME) $Button1 = GUICtrlCreateButton("OK ", 50, 55, 75, 25) $Button2 = GUICtrlCreateButton("Cancel", 198, 55, 75, 25) $Label = GUICtrlCreateLabel("", 30, 15, 300, 28) GUISetState() $timer = TimerInit() $tHold = 10 GUICtrlSetData($Label, "Backburner Server Will Run in about " & $tHold & " Secondes") GUICtrlSetData($Button1, "Ok " & $tHold) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button1 Runner($File_Name) ExitLoop Case $msg = $Button2 ExitLoop EndSelect If TimerDiff($timer) >= 1000 Then $tHold = $tHold - 1 GUICtrlSetData($Label, "Backburner Server Will Run in about " & $tHold & " Secondes") GUICtrlSetData($Button1, "Ok " & $tHold) $timer = TimerInit() If $tHold = 0 Then Runner($File_Name) ExitLoop EndIf EndIf WEnd GUIDelete($GUI2) EndFunc ;==>CountDown Func Runner($_File) Local $Script = 'Sleep(1000)' & @CRLF & 'Run("' & $_File & '")' Local $file_loc = @DesktopDir & "\Killer.au3" FileDelete($file_loc) FileWrite($file_loc, $Script) If @Compiled = 1 Then $file_exe = FileGetShortName(@AutoItExe & ' /AutoIt3ExecuteScript "' & $file_loc & '"') Run($file_exe & " ") Else $file_au3 = FileGetShortName($file_loc) Run(@AutoItExe & " " & $file_au3 & " ") EndIf EndFunc ;==>Runner 8) Link to comment Share on other sites More sharing options...
CGAnimator Posted May 1, 2009 Author Share Posted May 1, 2009 thank you.... thank you.... thank you.... sooooooooooooooooooo much Now it works just fine thanx 4 all help Link to comment Share on other sites More sharing options...
Valuater Posted May 1, 2009 Share Posted May 1, 2009 thank you.... thank you.... thank you.... sooooooooooooooooooo much Now it works just fine thanx 4 all help Welcome... I do remember that sometimes the Run() command does not like spaces. IF you have a problem, You can try this.. $File_Name = FileGetShortName($File_Name) Runner($File_Name) 8) 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