Allow only one instance of compiled script

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Mbrower
Newbie
Posts: 8
Joined: Mon Dec 18, 2006 7:35 pm

Allow only one instance of compiled script

Post by Mbrower » Fri Jan 12, 2007 5:35 am

Great product and a great forum. Normally I can find the answers by searching the forum but this time I have been unsuccessfull.

How can I prevent a user from accidently running a compiled macro multiple times by clicking on an exe more than once?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Jan 12, 2007 7:41 am

Here are two methods ......

1. First line of macro could rename itself.
Last line of macro could rename itself back to normal.

OR

2. First line checks for a temp file exists or for an INI value. Quit or Run based on results.
Second line creates a temp file or writes a value to an INI file.
Do Stuff
Last line deletes the temp file or changes the INI value.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jan 12, 2007 9:17 am

I would use a registry key. Otherwise you need to know which path to store the INI file in and if there are multiple copies of the exe in different locations this could be an issue. But all copies could access same registry key:

Code: Select all

RegistryReadKey>HKEY_CURRENT_USER,Software\MyEXE,Running,isRunning
If>isRunning<>TRUE
  HKEY_CURRENT_USER,Software\MyEXE,Running,TRUE
  ..
  .. rest of your macro code here
  ..
  RegistryWriteKey>HKEY_CURRENT_USER,Software\MyEXE,Running,FALSE
Endif
Now only one copy of the exe can actually do anything at a time.
Last edited by Marcus Tettmar on Fri Jan 12, 2007 2:36 pm, edited 2 times in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jan 12, 2007 2:34 pm

Will it ever run? If the key doesn't exist I don't think RegistryReadKey> will return anything. So doesn't the If> need to be something like;

If>{(%isRunning%=FALSE) or (%isRunning%="")}

for it to run the first time and write the key?

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jan 12, 2007 2:37 pm

I meant TRUE. Have edited accordingly.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Mbrower
Newbie
Posts: 8
Joined: Mon Dec 18, 2006 7:35 pm

Thanks

Post by Mbrower » Sat Jan 13, 2007 12:33 am

Thank you all,

I was already writing to an ini file so I used that method. Tested and it is working fine.

Thanks again

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Jan 15, 2007 3:56 pm

Another solution would be to add IfWindowOpen>Compiled Macros Dialog name,exit at the beginning of the script. That will shut the 2nd instant down immediately.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Mon Jan 15, 2007 5:12 pm

There is a potential weakness of using a registry key for this:
  • - user fires up macro
    - macro updates registry to store value to denote "macro is running"
    - power failure happens or user shuts off power to PC so there is no chance for the macro to change the registry value
    - later, PC is powered up, user runs macro, macro checks registry, value indicates "macro is running" (even though it isn't) and macro shuts down... user can no longer run the macro.
Rain's solution is the simplest and doesn't have the above weakness...
Rain wrote:Another solution would be to add IfWindowOpen>Compiled Macros Dialog name,exit at the beginning of the script. That will shut the 2nd instant down immediately.
Thanks for posting that Rain and take care all...
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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