It would be very useful if the
Process commands (
Exist,
Close,
Wait, etc.) offered the option to limit their scope to processes running in the same session as the script, which I'm guessing is what most people actually intend when using these commands. Scripts that run in multi-user environments like a server O/S (or even a workstation O/S where "Switch user" may be in use) and in which these commands are used "naively", could wind up getting fooled by (or closing) processes running in other sessions, especially likely if the script is running elevated.
Workarounds are available
if the script's author is aware of the "danger", but they're tedious to implement: for example, the script could first determine its session ID with the following commands
Code: Select all
PID := DllCall("GetCurrentProcessId")
DllCall("ProcessIdToSessionId", "UInt", PID, "UInt*", SessionID)
and then run, capture, and parse the output of
Code: Select all
TaskList.exe /FI "IMAGENAME eq targetprocess.exe" /FI "SESSION eq %SessionID%" /FO CSV /NH
to determine the PIDs of only the matching process(es) running in the current session.
If this is not easily implemented, the possibility of accidentally operating on processes in other sessions should maybe be mentioned in the documentation, along with workaround examples.
Jacques.