Check if .exe-file, WITH A PATH(!!!), is running, from within a bat-file?
-
When I search on the Internet, I find millions of web pages explaining how to check if a .exe-file is running, from within a .bat-file. However, I can't find a single page explaining what to do if you have several .exe-files with identical names and you only want to check an .exe-file that resides in a specific folder. Can anybody please help me, what's the way to detect if the file C:\MyProject\bin\release\MyApplication.exe is running, but at the same time completely ignore C:\MyProject\bin\debug\MyApplication.exe?
-
When I search on the Internet, I find millions of web pages explaining how to check if a .exe-file is running, from within a .bat-file. However, I can't find a single page explaining what to do if you have several .exe-files with identical names and you only want to check an .exe-file that resides in a specific folder. Can anybody please help me, what's the way to detect if the file C:\MyProject\bin\release\MyApplication.exe is running, but at the same time completely ignore C:\MyProject\bin\debug\MyApplication.exe?
In the absence of a language specification: [GetProcessImageFileNameA function (psapi.h) - Win32 apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessimagefilenamea)
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
When I search on the Internet, I find millions of web pages explaining how to check if a .exe-file is running, from within a .bat-file. However, I can't find a single page explaining what to do if you have several .exe-files with identical names and you only want to check an .exe-file that resides in a specific folder. Can anybody please help me, what's the way to detect if the file C:\MyProject\bin\release\MyApplication.exe is running, but at the same time completely ignore C:\MyProject\bin\debug\MyApplication.exe?
Using EnumProcesses / OpenProcess / GetModuleFileName you can get the full path names of all the running exe files. See example: [Enumerating All Processes - Win32 apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/psapi/enumerating-all-processes) BTW, what do you mean by "... from within a .bat-file."?
-
Using EnumProcesses / OpenProcess / GetModuleFileName you can get the full path names of all the running exe files. See example: [Enumerating All Processes - Win32 apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/psapi/enumerating-all-processes) BTW, what do you mean by "... from within a .bat-file."?
-
When I search on the Internet, I find millions of web pages explaining how to check if a .exe-file is running, from within a .bat-file. However, I can't find a single page explaining what to do if you have several .exe-files with identical names and you only want to check an .exe-file that resides in a specific folder. Can anybody please help me, what's the way to detect if the file C:\MyProject\bin\release\MyApplication.exe is running, but at the same time completely ignore C:\MyProject\bin\debug\MyApplication.exe?
@echo off
set "workdir=C:\MyProject\bin\release"
set "workdir=%workdir:\=\\%"setlocal enableDelayedExpansion
for /f "usebackq tokens=* delims=" %%a in (`
wmic process where 'CommandLine like "%%!workdir!%%" and not CommandLine like "%%RuntimeBroker%%"' get CommandLine^,ProcessId /format:value
`) do (
for /f "tokens=* delims=" %%G in ("%%a") do (
if "%%G" neq "" (
rem echo %%G
set "%%G"
rem echo !ProcessId!
goto :TheApplicationIsRunning
)
)
)echo The application is not running
exit /B:TheApplicationIsRunning
echo The application is running
exit /B -
@echo off
set "workdir=C:\MyProject\bin\release"
set "workdir=%workdir:\=\\%"setlocal enableDelayedExpansion
for /f "usebackq tokens=* delims=" %%a in (`
wmic process where 'CommandLine like "%%!workdir!%%" and not CommandLine like "%%RuntimeBroker%%"' get CommandLine^,ProcessId /format:value
`) do (
for /f "tokens=* delims=" %%G in ("%%a") do (
if "%%G" neq "" (
rem echo %%G
set "%%G"
rem echo !ProcessId!
goto :TheApplicationIsRunning
)
)
)echo The application is not running
exit /B:TheApplicationIsRunning
echo The application is running
exit /BIs it your solution?
-
Is it your solution?
-
Congrats! :)
-
Congrats! :)
-
@echo off
set "workdir=C:\MyProject\bin\release"
set "workdir=%workdir:\=\\%"setlocal enableDelayedExpansion
for /f "usebackq tokens=* delims=" %%a in (`
wmic process where 'CommandLine like "%%!workdir!%%" and not CommandLine like "%%RuntimeBroker%%"' get CommandLine^,ProcessId /format:value
`) do (
for /f "tokens=* delims=" %%G in ("%%a") do (
if "%%G" neq "" (
rem echo %%G
set "%%G"
rem echo !ProcessId!
goto :TheApplicationIsRunning
)
)
)echo The application is not running
exit /B:TheApplicationIsRunning
echo The application is running
exit /B