Goto a label when script manually closed

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

kilborr
Newbie
Posts: 8
Joined: Wed Jun 10, 2009 7:32 am

Goto a label when script manually closed

Post by kilborr » Wed Jun 10, 2009 7:37 am

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

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

goto>label

Post by gdyvig » Wed Jun 10, 2009 1:22 pm

Hi Kilborr,


Try OnEvent triggered by the desired key stroke.

OnEvent will run a subroutine which can contain your exit code.


Gale

kilborr
Newbie
Posts: 8
Joined: Wed Jun 10, 2009 7:32 am

Re: goto>label

Post by kilborr » Wed Jun 10, 2009 2:43 pm

gdyvig wrote:Hi Kilborr,


Try OnEvent triggered by the desired key stroke.

OnEvent will run a subroutine which can contain your exit code.


Gale
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 ???

thanks a lot

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

OnEvent

Post by gdyvig » Wed Jun 10, 2009 3:58 pm

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

kilborr
Newbie
Posts: 8
Joined: Wed Jun 10, 2009 7:32 am

Re: OnEvent

Post by kilborr » Wed Jun 10, 2009 4:17 pm

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
Sorry, it's another program which shutdown windows, it's not really "manually"

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 :roll:

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

OnEvent should work.

Post by gdyvig » Wed Jun 10, 2009 8:45 pm

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.


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>

Note that OnEvent goes to a SRT label instead of a GoTo label. You don't really need the OptionalShutdownCode label.


Gale
Last edited by gdyvig on Wed Jun 10, 2009 10:27 pm, edited 1 time in total.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jun 10, 2009 10:16 pm

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

kilborr
Newbie
Posts: 8
Joined: Wed Jun 10, 2009 7:32 am

Post by kilborr » Thu Jun 11, 2009 7:18 am

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.

kilborr
Newbie
Posts: 8
Joined: Wed Jun 10, 2009 7:32 am

Re: OnEvent should work.

Post by kilborr » Thu Jun 11, 2009 7:19 am

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


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>

Note that OnEvent goes to a SRT label instead of a GoTo label. You don't really need the OptionalShutdownCode label.


Gale
OK i try this, but

Code: Select all

OnEvent>WINDOW_NOTOPEN,Program Manager,2,ExitScript
2 => displayed windows, but "program manager" is not displayed so... it's maybe "1"

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
with "explorer.exe" but the test script write to file as soon as i execute it, whereas i had not shudown computer, so "explorer.exe" is still runing :(

('m runing 10.22 MS)

Thanks

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

"Program Manager" in French

Post by gdyvig » Thu Jun 11, 2009 2:44 pm

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

kilborr
Newbie
Posts: 8
Joined: Wed Jun 10, 2009 7:32 am

Post by kilborr » Thu Jun 11, 2009 2:53 pm

Sorry but i don't understand
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

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

The signal

Post by gdyvig » Thu Jun 11, 2009 3:30 pm

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:

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

kilborr
Newbie
Posts: 8
Joined: Wed Jun 10, 2009 7:32 am

Re: The signal

Post by kilborr » Thu Jun 11, 2009 3:59 pm

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:

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%
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
It doesn't work. I have "progman" in a variable but "onevent>WINDOW_NOTOPEN,variable,1,exit"

don't work, when windows shutdown, script is only closed without go to "exit" SR ... :roll:

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

"Gestionnaire de programmes"

Post by gdyvig » Thu Jun 11, 2009 4:57 pm

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

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Script already killed, of course.

Post by gdyvig » Fri Jun 12, 2009 4:20 am

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.



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

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts