Sign in to follow this  
Followers 0
wisem2540

Need GUI form to reopen

15 posts in this topic

So I have a script that has came along way.... When I click the snooze button, Its set to do a GUIDELETE and effectively close the form. My Goal is to have it Wait something like 1hour, and relaunch the same form. How can I get Autoit to start over at the $form1= line since there is no GOTO command?

#include 

#include 

#include 

#include 

#include 

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\my documents\my pictures\form1.kxf

$Form1 = GUICreate("BJC CE PACS SHUTDOWN SCRIPT", 301, 267, 237, 147)

GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Close")

GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Close")

GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Close")

$Label1 = GUICtrlCreateLabel("BJC Clinical Engineering Auto Shutdown Script", 11, 8, 278, 20)

GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

GUICtrlSetOnEvent(-1, "Label1Click")

$Label3 = GUICtrlCreateLabel("Created By:", 129, 85, 59, 17)

GUICtrlSetOnEvent(-1, "Label3Click")

$Label4 = GUICtrlCreateLabel("Chip Means", 120, 104, 88, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

GUICtrlSetOnEvent(-1, "Label4Click")

$Label5 = GUICtrlCreateLabel("Chip.Means@Bjc.org", 106, 133, 131, 20)

GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

GUICtrlSetOnEvent(-1, "Label5Click")

$Label6 = GUICtrlCreateLabel("For Support Call 636-717-3600", 7, 184, 286, 28)

GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")

GUICtrlSetOnEvent(-1, "Label6Click")

$Progress1 = GUICtrlCreateProgress(75, 40, 150, 17)

$Reboot = GUICtrlCreateButton("Reboot", 88, 227, 65, 25)

GUICtrlSetOnEvent(-1, "RebootClick")

$Snooze = GUICtrlCreateButton("Snooze", 165, 227, 65, 25)

GUICtrlSetOnEvent(-1, "Form1Close")

$Label2 = GUICtrlCreateLabel("%", 230, 42, 12, 17)

GUICtrlSetOnEvent(-1, "Label2Click")

$Label7 = GUICtrlCreateLabel("%", 242, 42, 12, 17)

GUICtrlSetOnEvent(-1, "Label7Click")

GUISetState(@SW_SHOW)

For $i = 0 To 100

GUICtrlSetData(8,$i,"")

GUICtrlSetData(11,$i,"")



Sleep(300)

Next

Run("Shutdown /r /t 0 /f")

Exit

#EndRegion ### END Koda GUI section ###







Func Form1Close()

GUIDelete($Form1)



EndFunc

Func Label1Click()



EndFunc

Func Label3Click()



EndFunc

Func Label4Click()



EndFunc

Func Label5Click()



EndFunc

Func Label6Click()



EndFunc

Func RebootClick()

Run("Shutdown /r /t 0 /f")

Exit



EndFunc

Share this post


Link to post
Share on other sites



Why don't you use GUISetState ?

GUISetState(@SW_HIDE, $Form1)
Sleep(3600000)
GUISetState(@SW_SHOW, $Form1)

If I hide the GUI, it stays running, only hidden correct? If the form is not closed in time, the machine will reboot

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I tried putting in a "Repeat function. And it does repeat. But it wont repeat again...almost like it cannot call the function again because it has passed it already. Can you not use functions that are higher in the script? For instance, if I have a Function defined on Line 10 and I try to Use that function on Line 20, should that not work?

For example. Function is on line 10 and On Line 20 I have

GUICtrlSetOnEvent(-1, "Repeat")

This works if the "Repeat Function is Below where line 20, but not above

Edited by wisem2540

Share this post


Link to post
Share on other sites

If I hide the GUI, it stays running, only hidden correct? If the form is not closed in time, the machine will reboot

Yes It' true but why will it reboot?

In that case you can use Task Scheduler. Use AT Command.

Share this post


Link to post
Share on other sites

Yes It' true but why will it reboot?

In that case you can use Task Scheduler. Use AT Command.

The Script is a reboot Script. If the Snooze button is not pressed in time, it will reboot. Cururently when you Push Snooze, the app closes... But What I would like is a true snooze. So I need it to be able to repeat after a predetermined time

Share this post


Link to post
Share on other sites

I also tried using a function to Call a function so that it would jump back up. That is not working either.....

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

So here is something interesting. I tried something new. This time, When I hit snooze, I had it set to go to a GUIDELETE command. and then to Call a "Start" function I made. So the GUIDELETE works, but then none of the buttons on the repeat screen work....almost like it creates an entirely different form after the other is closed

Notice how I have Minimize set to Close the form? When it repeats, I am able to minimize the form, whereas the first time through, everything works as it should.

What could cause this?

Edited by wisem2540

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hope this helps

#include <GUIConstantsEx.au3>

If Not @Compiled Then
MsgBox(32,"ERROR","Compile me first!")
Exit
EndIf

Opt("GUIOnEventMode", 1)

#region ### START Koda GUI section ###

$Form1 = GUICreate("BJC CE PACS SHUTDOWN SCRIPT", 301, 267, 237, 147)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

$Label1 = GUICtrlCreateLabel("BJC Clinical Engineering Auto Shutdown Script", 11, 8, 278, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Label1Click")

$Label3 = GUICtrlCreateLabel("Created By:", 129, 85, 59, 17)
GUICtrlSetOnEvent(-1, "Label3Click")

$Label4 = GUICtrlCreateLabel("Chip Means", 120, 104, 88, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Label4Click")

$Label5 = GUICtrlCreateLabel("Chip.Means@Bjc.org", 106, 133, 131, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Label5Click")

$Label6 = GUICtrlCreateLabel("For Support Call 636-717-3600", 7, 184, 286, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Label6Click")

$Progress1 = GUICtrlCreateProgress(75, 40, 150, 17)
$Prog = 0

$Reboot = GUICtrlCreateButton("Reboot", 88, 227, 65, 25)
GUICtrlSetOnEvent(-1, "Reboot")

$Snooze = GUICtrlCreateButton("Snooze", 165, 227, 65, 25)
GUICtrlSetOnEvent(-1, "Snooze")

$Label2 = GUICtrlCreateLabel("%", 230, 42, 12, 17)
GUICtrlSetOnEvent(-1, "Label2Click")

$Label7 = GUICtrlCreateLabel("%", 242, 42, 12, 17)
GUICtrlSetOnEvent(-1, "Label7Click")

GUISetState(@SW_SHOW)


#endregion ### END Koda GUI section ###

While 1
$Prog += 1
GUICtrlSetData(11, $Prog, "")
GUICtrlSetData(8, $Prog, "")
If $Prog = 100 Then Reboot()
Sleep(500)
WEnd

Func Snooze()
$Hour = @HOUR
$Hour += 1
If $Hour = 24 Then $Hour = 00
If StringLen($Hour) = 1 Then $Hour = "0" & $Hour
$Time = $Hour & ":" & @MIN
RunWait(@ComSpec & " /C " & "Schtasks /Create /SC ONCE /TN " & '"' & @ScriptName & '"' & " /TR " & '"' & @ScriptFullPath & '"' & " /ST " & $Time & " /Z", "", @SW_HIDE)
Exit
EndFunc ;==>Snooze

Func Form1Close()
GUIDelete($Form1)
Exit
EndFunc ;==>Form1Close


Func Label1Click()
EndFunc ;==>Label1Click


Func Label2Click()
EndFunc ;==>Label2Click


Func Label3Click()
EndFunc ;==>Label3Click
 

Func Label4Click()
EndFunc ;==>Label4Click
 

Func Label5Click()
EndFunc ;==>Label5Click


Func Label6Click()
EndFunc ;==>Label6Click


Func Label7Click()
EndFunc ;==>Label7Click


Func Reboot()
Run("Shutdown /r /t 0 /f")
Exit
EndFunc ;==>Reboot

I was trying to schedule the task using AT.exe but apparently it didn't work.

So I used 'Schtasks.exe '. But It didn't work for me either because my services setting's are messed up. hope it works for you!

After you click Snooze button, Run command line and type "Schtasks /Query" and Press enter.

look for your script's name in the beginning. If it is there then everything is ok. the script will be launched again after an hour.

Edited by n1maS

Share this post


Link to post
Share on other sites

I see the concept, and it I like it. However, it does not work. Im working on trying to modify the scheduled task portion, but as you can tell, my coding isnt overly neat.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I see.

Remove "/Z" swicth. change this line

RunWait(@ComSpec & " /C " & "Schtasks /Create /SC ONCE /TN " & '"' & @ScriptName & '"' & " /TR " & '"' & @ScriptFullPath & '"' & " /ST " & $Time & " /Z", "", @SW_HIDE)

to

RunWait(@ComSpec & " /C " & "Schtasks /Create /SC ONCE /TN " & '"' & @ScriptName & '"' & " /TR " & '"' & @ScriptFullPath & '"' & " /ST " & $Time, "", @SW_HIDE)

It'll work then. but you have to remove the task manually :thumbsdown:

you can modify the scheduled task using "Schtasks /Change" command.

use "Schtasks /Change /?" to display help message.

Edited by n1maS

Share this post


Link to post
Share on other sites

I see.

Remove "/Z" swicth. change this line

RunWait(@ComSpec & " /C " & "Schtasks /Create /SC ONCE /TN " & '"' & @ScriptName & '"' & " /TR " & '"' & @ScriptFullPath & '"' & " /ST " & $Time & " /Z", "", @SW_HIDE)

to

RunWait(@ComSpec & " /C " & "Schtasks /Create /SC ONCE /TN " & '"' & @ScriptName & '"' & " /TR " & '"' & @ScriptFullPath & '"' & " /ST " & $Time, "", @SW_HIDE)

It'll work then. but you have to remove the task manually :thumbsdown:

you can modify the scheduled task using "Schtasks /Change" command.

use "Schtasks /Change /?" to display help message.

I suppose in the Reboot function, you could add a line that removes the task created by the snooze. That would solve that issue, correct? Anyway, I still cannot get that scheduled task to create. Does it matter that I am testing on XP?

Share this post


Link to post
Share on other sites

Another issue I am running into is that when I try to create the scheduled task from command line, its asking me to supply a username and password for an admin. The issue comes up where all of my Admin passwords are not always the same. Is there a way to do this without that, or will that just keep it from running without a logged on user?

Share this post


Link to post
Share on other sites

Ive been playing with this more and more. And I simply dont think a scheduled task will work. Even if I schedule it manually, if I switch users, I cannot "see" the script run. It runs under the specified user account, hidden from the currently logged in user.

So now im back to Square one There has to be an easer way to make this script start over if I push a button in the GUI....

Any Help?

Share this post


Link to post
Share on other sites

I have fixed this. Thanks

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