Check if a program is running
brucine Posted messages 24710 Registration date Status Member Last intervention -
Hello,
Suppose I want to see how long a program has been running, and I want to do this for any program whose path I can enter into my script as a variable: for starters, no problem, I'll launch it by START and log the system time.
When I close it this time via the graphical interface, I can check with the TASKLIST command, with or without switches, if the process is open; as soon as it is no longer running, I log the system time again and calculate the difference.
For example, with (anything...) Notepad, I can write something like:
tasklist | find /i "Notepad.exe">nul && GOTO RUN || GOTO STOP
Now the trouble begins if I want to do the same thing (still anything...) with the new Windows 10 or 11 calculator (it's no longer calc.exe but an application with an enigmatic name) or more generally any program whose executable name is different from that of the process: I can't specify the process name unless I go look for it in the task manager.
Is there a way for me to retrieve the process name that will be launched from the name of the executable in question?
Thank you.
1 answer
Hello,
According to my research, it seems that the name of the process ("image name" in English) is always the same as that of the executable:
https://stackoverflow.com/questions/35173913/is-the-process-name-always-the-name-of-the-exe
If you launch a program via the START command, that implies you know its path, and if you know the path, you can find the name of the executable, so the loop is closed, as they say.
An example with the Windows 10 calculator:
"C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_11.2210.0.0_x64__8wekyb3d8bbwe\CalculatorApp.exe"
Hello,
If you say so...
I remember being exposed to this situation a long time ago; of course, I no longer recall which program it was for, and I'm nitpicking since, indeed, the question is very theoretical regarding "generalizing to any program".
I don't understand anything about programming; the name displayed in the task manager would be the value of Assembly Information Title, which would be purely at the developer's discretion (even though, indeed, it wouldn't be common for them to complicate things and use a different name from the executable).
https://stackoverflow.com/questions/56708062/how-to-have-a-different-process-name-for-current-process-name-in-task-manager
https://stackoverflow.com/questions/13604777/set-task-manager-file-name
In such a hypothesis, there is anyway an approximate workaround (there might be an intruder in between) that I haven't tested: TASKLIST at the start of the script, START the program, TASKLIST immediately after and extract the additional line between the two logs.
To summarize and conclude:
.
1) The name of the process is always identical to the name of the executable, which is the name displayed by the TASKLIST command.
2) The task manager does not display the process name by default, but the process title, which corresponds to the value of "Assembly Information Title" in a Visual Studio project.
3) The process name can be obtained from the task manager by going into the process details.
.
Returning to your issue, it is indeed possible to perform a TASKLIST before and after, but this is not advisable as we cannot rule out the possibility of an intruder skewing the manipulation.
.
For me, the best solution is to "hardcode" the process name based on the name of the executable.
In any case, none of us noticed that, whether the name of the process is the same or not, and even if there were no intruders, my question is absurd: you can't launch a program graphically to extract the TASKLIST name into a variable that is meant to launch the program in the same script.