Jump to content

Kill script instance but only if Hotkey WASN'T used for it?

Recommended Posts

I have a script that runs either one of two functions depending upon which of two hotkeys I've created are used. Once I use one of the hotkeys to run one of those functions I need a new instance of that script to be run so that it, too, can accept the usage of those hotkeys. So I've added code that runs a new instance once one of the hotkeys is used. When the function I'm running completes its work it closes the instance of the script it is run from. However, there are times when I have to manually intervene and close the script myself. Because of this setup, overtime I end up with many unused and unneeded instances of the script running in the background. What I need is a way to prevent any more than 1 instance of the script from running at a time but only provided that no hotkeys have been used for those instances. Once I use a hotkey for an instance, the script remains running in the background according to the function chosen. So the name of ALL of the instances of the scripts, both the ones where the chosen function has started running and the ones waiting for a hotkey to be pressed, are all the same.

How can I accomplish this?

Link to post
Share on other sites

I'm not 100% sure on what you're asking here, but it sounds like you could write the script's PID to the registry under a specific path. Then when the script is launched, it will first check to see if the Registry has a value (and if needed) can check if that PID exists.

; <Script #1 - Main>
HotKeySet("a", "NewScript")

While True

Func NewScript()

; <Script #2 - Child>

$PID = RegRead($RegistryFullPath, $ValueName)
If @Error Then $PID = ""
If $PID = "" Then
    RegWrite($RegistryFullPath, $ValueName, "REG_SZ", @AutoItPID)
    ; Other code
    RegDelete($RegistryFullPath, $ValueName)


All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.


My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...