A question about finding & closing executables.

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

A question about finding & closing executables.

Post by PaulSR » Mon Mar 17, 2014 1:50 pm

Hi,

I've got a compiled script which a few people are running at different times. What I'm currently looking at are times where it has been possible for a single user to end up with multiple instances of the macro executable running concurrently (either running it again whilst the last instance is still running or because it became stuck).

What I want to do is at the start of the script look to see if the program is running already and if so close it down. I thought I'd found a pretty straightforward solution by getting the window list and checking for "Shift+Esc To Stop" then getting the window handle and doing a close on that but this doesn't seem to work properly all the time.

Is there a way of identifying what's running in the system tray and if it's found forcing it to shutdown? I've noticed that manually pressing "Shift+Esc" doesn't always work in stopping the executable from running either.

Thanks in advance!

Here's my not good enough attempt :

Code: Select all

GetWindowList>ListOfWindows
MessageModal>ListOfWindows
Position>Shift+Esc To Stop,ListOfWindows,1,Where
If>{%Where%>0}
    Let>WIN_USEHANDLE=1
    GetWindowHandle>Shift+Esc To Stop,nHandle
    CloseWindow>%nHandle%
Else
    MessageModal>Couldn't see it
EndIf

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Post by PaulSR » Mon Mar 17, 2014 2:13 pm

I think I need to improve my search skills - I look and find nothing, start a thread and then almost instantly find what I need.

This thread Marcus replied to in 2006 fits my needs perfectly :

viewtopic.php?t=3226&sid=e0af98904ada5f ... 89b799133a

Hopefully it helps somebody else and this thread isn't completely useless :wink:

EDIT : Found this useful as well :

http://www.mjtnet.com/forum/viewtopic.php?t=2574

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1390
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Mon Mar 17, 2014 10:38 pm

Thank you for sharing the solution. That goes a long way towards helping others. :D
Yes, we have a Custom Scripting Service. Message me or go here

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