I have a batch script which is run from an AT command, and may get run more than once. When it starts, I need it to detect if it already running, and if so, exit (the second one) immediately.
- It must be robust, and handle if the scripts exits unexpectedly (i.e. so I can't set a flag on entry and clear it on exit)
- It must run in a Remote Desktop session
- I'm stuck on XP with Powershell v2, but don't mind writing a little exe if I can't do it in batch/powershell or vbs
- The script must run minimised, so I start it with Start "NAME" /MIN %COMSPEC% /C "MyScript.bat"
- Other cmd windows may be open so I need to check the running script
- The batch script runs as SYSTEM user, but I can't use any WMI
I was using PowerShell Get-Process to look at MainWindowTitle, but this didn't work when remote connecting to the computer as the script may be running, but not displayed in this remote connection instance. I this case, the cmd process is seen by Get-Process, but the MainWindowTitle is blank.
I've tried Get-Process and looked at the expanded StartInfo.EnvironmentVariables property, but can't see how to create an env var so that it appears in the property.
I thought about using /WAIT in the start command, then the AT will remain open until it finishes, but the script containing the AT is not minimised