Goto a label when script manually closed
Moderators: JRL, Dorian (MJT support)
Goto a label when script manually closed
Hi everybody,
I had made a script which is running everytime on my computer.
I have a label which write to a file some informations taken from the script
But i want to know how to go to this label automatically when i close manually the script (right click or with shortcut)
I hope you understand my question, because i'm french ^^
thanks
I had made a script which is running everytime on my computer.
I have a label which write to a file some informations taken from the script
But i want to know how to go to this label automatically when i close manually the script (right click or with shortcut)
I hope you understand my question, because i'm french ^^
thanks
goto>label
Hi Kilborr,
Try OnEvent triggered by the desired key stroke.
OnEvent will run a subroutine which can contain your exit code.
Gale
Try OnEvent triggered by the desired key stroke.
OnEvent will run a subroutine which can contain your exit code.
Gale
Re: goto>label
OK ... I "force" stop the script when i shutdown windows (because the script is so complex so i doest want to shutdown windows inside the script...) so can "OnEvent" detect the shutdown signal to go to a specifique label ???gdyvig wrote:Hi Kilborr,
Try OnEvent triggered by the desired key stroke.
OnEvent will run a subroutine which can contain your exit code.
Gale
thanks a lot
OnEvent
You are saying the script runs continuously and you want it to stop gracefully when you manually shut down Windows.
You can use an OnEvent KEY_DOWN event to detect you clicked whatever key you want to use as a trigger for the script to exit.
You can also use OnEvent WINDOW_OPEN for the "Shut Down Windows" dialog that displays when you click the ESC key too many times. That window can also be a trigger for the script to exit.
You can also use OnEvent WINDOW_NOTOPEN for the "Program Manager" window, the last window to close before Windows shuts down.
You mentioned the complexity of your script. Is the real problem you are not sure how to gracefully shut everything down in your script before Windows closes?
Gale
You can use an OnEvent KEY_DOWN event to detect you clicked whatever key you want to use as a trigger for the script to exit.
You can also use OnEvent WINDOW_OPEN for the "Shut Down Windows" dialog that displays when you click the ESC key too many times. That window can also be a trigger for the script to exit.
You can also use OnEvent WINDOW_NOTOPEN for the "Program Manager" window, the last window to close before Windows shuts down.
You mentioned the complexity of your script. Is the real problem you are not sure how to gracefully shut everything down in your script before Windows closes?
Gale
Re: OnEvent
Sorry, it's another program which shutdown windows, it's not really "manually"gdyvig wrote:You are saying the script runs continuously and you want it to stop gracefully when you manually shut down Windows.
You can use an OnEvent KEY_DOWN event to detect you clicked whatever key you want to use as a trigger for the script to exit.
You can also use OnEvent WINDOW_OPEN for the "Shut Down Windows" dialog that displays when you click the ESC key too many times. That window can also be a trigger for the script to exit.
You can also use OnEvent WINDOW_NOTOPEN for the "Program Manager" window, the last window to close before Windows shuts down.
You mentioned the complexity of your script. Is the real problem you are not sure how to gracefully shut everything down in your script before Windows closes?
Gale
The sript interact continously with a web page.
I don't want to shutdown windows inside the script because i never shutdown windows at the same time, i never no that, dependig of many parameters
I want to shutdown windows to do energy saving during a part of the night but i don't know where is the progress of the script at this time "X"
So i want the script "detect" shutdown signal to do a last "Label>"
thanks

OnEvent should work.
Hi Kilborr,
The OnEvent for the "Program Manager" window closing should work. When "Program Manager" is closed, you desktop has disappeared. Macro Scheduler should still be running unless your other program already stopped Macro Scheduler.
Note that OnEvent goes to a SRT label instead of a GoTo label. You don't really need the OptionalShutdownCode label.
Gale
The OnEvent for the "Program Manager" window closing should work. When "Program Manager" is closed, you desktop has disappeared. Macro Scheduler should still be running unless your other program already stopped Macro Scheduler.
Code: Select all
OnEvent>WINDOW_NOTOPEN,Program Manager,2,ExitScript
SRT>ExitScript
//Added this in response to JRL's post.
//Write message to a text file here
Exit>
//Or have the GoTo do the exit
GoTo>OptionalShutdownCode
END>ExitScript
Label>OptionalShutdownCode
//Write message to a text file here.
Exit>
Gale
Last edited by gdyvig on Wed Jun 10, 2009 10:27 pm, edited 1 time in total.
Gale,
The following script is an altered version of what you posted. I compiled it and ran it then shutdown the computer. No log file is created.
I think the method mentioned HERE might work.
The following script is an altered version of what you posted. I compiled it and ran it then shutdown the computer. No log file is created.
I think the method mentioned HERE might work.
Code: Select all
// COMPILE_OPTS|C:\Documents and Settings\dickl\My Documents\Macro Scheduler 11\Detect Process not running.exe||CONSOLE=0|INCLUDES=1|
OnEvent>WINDOW_NOTOPEN,Program Manager,2,ExitScript
Let>kk=0
SRT>ExitScript
Label>Loop
add>kk,1
DateStamp>%temp_dir%shutdownlog.txt,%kk%
Goto>Loop
END>ExitScript
Label>ActionLoop
Wait>0.01
Goto>ActionLoop
JRL wrote:Gale,
The following script is an altered version of what you posted. I compiled it and ran it then shutdown the computer. No log file is created.
I think the method mentioned HERE might work.
Code: Select all
// COMPILE_OPTS|C:\Documents and Settings\dickl\My Documents\Macro Scheduler 11\Detect Process not running.exe||CONSOLE=0|INCLUDES=1| OnEvent>WINDOW_NOTOPEN,Program Manager,2,ExitScript Let>kk=0 SRT>ExitScript Label>Loop add>kk,1 DateStamp>%temp_dir%shutdownlog.txt,%kk% Goto>Loop END>ExitScript Label>ActionLoop Wait>0.01 Goto>ActionLoop
I don't understand your answer, and i have already view the topic linked, i think it don't answer to my question.
Re: OnEvent should work.
OK i try this, butgdyvig wrote:Hi Kilborr,
The OnEvent for the "Program Manager" window closing should work. When "Program Manager" is closed, you desktop has disappeared. Macro Scheduler should still be running unless your other program already stopped Macro Scheduler.
Note that OnEvent goes to a SRT label instead of a GoTo label. You don't really need the OptionalShutdownCode label.Code: Select all
OnEvent>WINDOW_NOTOPEN,Program Manager,2,ExitScript SRT>ExitScript //Added this in response to JRL's post. //Write message to a text file here Exit> //Or have the GoTo do the exit GoTo>OptionalShutdownCode END>ExitScript Label>OptionalShutdownCode //Write message to a text file here. Exit>
Gale
Code: Select all
OnEvent>WINDOW_NOTOPEN,Program Manager,2,ExitScript
I'm french, i have no windows named "program manager"
I try
Code: Select all
OnEvent>WINDOW_NOTOPEN,explorer,1,ExitScript
SRT>ExitScript
WriteLn>C:\testOut.txt,r,here it's the text
Exit>
END>ExitScript

('m runing 10.22 MS)
Thanks
"Program Manager" in French
Hi Kilborr,
I was thinking that might be a problem.
Try this:
Open up View System Windows.
Scroll to the bottom.
On an English system you will see:
+ 131248 - Progman "Program Manager"
The number is a dynamically assigned handle, it will be different for every Windows session.
Progman is the class of the Program Manager Window.
Do you see Progman in the French version?
Whatever you see in quotes after Progman should be the French spelling of "Program Manager".
Another way to do it is in a script with the GetWindowList command, the last window listed should be the Program Manager title.
Gale
I was thinking that might be a problem.
Try this:
Open up View System Windows.
Scroll to the bottom.
On an English system you will see:
+ 131248 - Progman "Program Manager"
The number is a dynamically assigned handle, it will be different for every Windows session.
Progman is the class of the Program Manager Window.
Do you see Progman in the French version?
Whatever you see in quotes after Progman should be the French spelling of "Program Manager".
Another way to do it is in a script with the GetWindowList command, the last window listed should be the Program Manager title.
Gale
Sorry but i don't understand
I don't see interest of Program Manager in my script, really
But i have this in the MS system windows
Nobody know if we can get the shutdown signal to use it in a MS script ?
thanks
Open up View System Windows.
Scroll to the bottom.
On an English system you will see:
+ 131248 - Progman "Program Manager"
I don't see interest of Program Manager in my script, really


But i have this in the MS system windows
Nobody know if we can get the shutdown signal to use it in a MS script ?
thanks
The signal
The Program Manager window is always there during a Windows session. When it disappears, that is your signal to exit your script.
Here is a simple script to get the Program Manager window title in any language:
Use the window title found by this script as your signal. When it disappears - that is your signal Windows is closing and you need to exit your script.
Gale
Here is a simple script to get the Program Manager window title in any language:
Code: Select all
//Close all windows before running this script
//Run this script from Start>Run
GetActiveWindow>window_title,X,Y
MDL>Progman:%window_title%
Gale
Re: The signal
It doesn't work. I have "progman" in a variable but "onevent>WINDOW_NOTOPEN,variable,1,exit"gdyvig wrote:The Program Manager window is always there during a Windows session. When it disappears, that is your signal to exit your script.
Here is a simple script to get the Program Manager window title in any language:
Use the window title found by this script as your signal. When it disappears - that is your signal Windows is closing and you need to exit your script.Code: Select all
//Close all windows before running this script //Run this script from Start>Run GetActiveWindow>window_title,X,Y MDL>Progman:%window_title%
Gale
don't work, when windows shutdown, script is only closed without go to "exit" SR ...

"Gestionnaire de programmes"
Hi Kilborr,
English:"Program Manager"
French:"Gestionnaire de programmes"
The GetWindowList, GetActiveWindow, and MS System Windows should have returned "Gestionnaire de programmes".
Try
OnEvent>WINDOW_NOTOPEN,Gestionnaire de programmes,2,ExitScript
Or try:
OnEvent>WINDOW_NOTOPEN,Gestionnaire de programmes*,2,ExitScript
Gale
English:"Program Manager"
French:"Gestionnaire de programmes"
The GetWindowList, GetActiveWindow, and MS System Windows should have returned "Gestionnaire de programmes".
Try
OnEvent>WINDOW_NOTOPEN,Gestionnaire de programmes,2,ExitScript
Or try:
OnEvent>WINDOW_NOTOPEN,Gestionnaire de programmes*,2,ExitScript
Gale
Script already killed, of course.
My OnEvent is not working because the script was killed before Program Manager window closed.
The link JRL posted should work. I think setting up Windows shutdown and logoff scripts are the answer. They can provide the signal your Macro Scheduler script needs. The shutdown script can be a bat file that creates a file, that can be your signal to use with OnEvent.
This link shows how to use the group policy editor to create a shuttdown script.
http://www.windows-help-central.com/win ... cript.html
You may need to do something similar for a logoff script.
If your needs are simpler, here is a short script that will exit if you indicate you might be logging off or shutting down.
The link JRL posted should work. I think setting up Windows shutdown and logoff scripts are the answer. They can provide the signal your Macro Scheduler script needs. The shutdown script can be a bat file that creates a file, that can be your signal to use with OnEvent.
This link shows how to use the group policy editor to create a shuttdown script.
http://www.windows-help-central.com/win ... cript.html
You may need to do something similar for a logoff script.
If your needs are simpler, here is a short script that will exit if you indicate you might be logging off or shutting down.
Code: Select all
//Does not work, script already killed
OnEvent>WINDOW_NOTOPEN,Program Manager*,2,ExitScript, Program Manager gone
//Works, but user may back out of these screens
OnEvent>WINDOW_OPEN,Log Off Windows*,2,ExitScript, Log Off
OnEvent>WINDOW_OPEN,Shut Down Windows*,2,ExitScript, Shut Down
SRT>ExitScript
TimeStamp>C:\mjt\ExitScript.txt,ExitScript: %ExitScript_Var_1%
Exit>
END>ExitScript
Let>x=0
Repeat>x
Let>x=x+1
TimeStamp>C:\mjt\ExitScript.txt,%x%
wait>0.01
Until>x=-10