Here's how I interpreted Lexikos's suggestion:
In the auto-execute
section (I'd recommend the very first lines), have an instance of a script look for other instances of the script. If it finds a match (i.e. more than one - one being itself, I expect), it should use PostMessage
to send a message to the first instance of the script. (This is the only time a message should be sent, so it shouldn't create a race condition, because it's a one-time check.) Upon receiving the message, it'll execute a function per OnMessage
() run in the auto-execute and can then close itself.
But now I'm realizing that because the second instance isn't admin, and the first instance is admin, that you would need to include your
If !( A_IsAdmin )
check. I don't think it has to be integrated into the idea above, like you talked about in your edit1 and edit2 in the post above. (Or you could just make the script do the Run and ExitApp commands assuming it came back with a positive result on finding other instances, after it would PostMessage them to close.)
As to the point of "do nothing and ExitApp", you can use that same check for other scripts as Lexikos mentioned and if it returns true (again, I expect more than one identified window, as it should identify itself), just ExitApp. Make that your first task in the script.