Bagel Posted September 13, 2019 Share Posted September 13, 2019 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 comment Share on other sites More sharing options...
seadoggie01 Posted September 14, 2019 Share Posted September 14, 2019 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 Sleep(100) WEnd Func NewScript() Run($FullScriptPath) EndFunc ; <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) EndIf All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Deye Posted September 14, 2019 Share Posted September 14, 2019 Bagel, Doesn't sound at all hard to do, but it would be easier to see what works if you can make a small reproducer for it Deye Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now