#CHECK TO SEE IF WINDOWS 10 IS ACTIVATED .EXE#
exe suffix is mandatory in this case where you pass the executable name): off More simple usage where it uses the name if the process as an argument (the. QPROCESS command is not so powerful as TASKLIST and is limited in showing only 12 symbols of process name but should be taken into consideration if TASKLIST is not available. QPROCESS * | find /i "%process_to_check%" >nul 2>&1 & (Įcho process %process_to_check% is runningĮcho process %process_to_check% is not running
Set process_to_check=%process_to_check:~0,12% :: If other tool is used the line bellow could be deleted :: QPROCESS can display only the first 12 symbols of the running process :: first argument is the process you want to check if running
If "%~1" equ "" echo pass the process name as forst argument & exit /b 1 I like the WMIC and TASKLIST tools but they are not available in home/basic editions of windows.Another way is to use QPROCESS command available on almost every windows machine (for the ones that have terminal services - I think only win XP without SP2, so practialy every windows machine): off I know sometimes reading batch/command-line can be kind of confusing sometimes if you're kind of a newbie, like me. ::give this batch a few seconds timer to avoid a false offįOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x = %EXE% goto ProcessFoundĪnyway, I hope that helps. ::Also, some large programs take a while to no longer show as not running, so ::notepad.exe to the process you'd like to track ::You can Copy and Paste this into an empty batch file and change the name of ::Process names are CASE SENSITIVE, so notepad.exe works but Notepad.exe does NOT TrueY's modified Answer: ::Change the name of notepad.exe to the process. Let me clear things up to hopefully save some time for the next person. TrueY's answer seemed the most elegant solution, however, I had to do some messing around because I didn't understand what exactly was going on. REM If Running label not exists, it will loop over all found tasks (Sorry, but I do not deal with the SPACE issue here, as it seems to be pretty rare and a solution is shown for it) SETLOCAL EnableExtensions The problem with the GOTO-less solution, that is may run the condition part (and the ELSE part) multiple times, so it is a bit messy as it has to quit the loop anyway. Ideally the targeted application should already mutex itself to prevent multiple instances, but that is a topic for another SO question and is not necessarily applicable to the subject of this question. Should you want one anyway, either a GOTO or a flag variable is indicated. There is no guarantee that there be only a single instance running when you run this script. Keep in mind that if you add an ELSE clause then it will be executed once for every instance of the application that is already running. The only concern is whether or not the process we are targeting has space(s).
#CHECK TO SEE IF WINDOWS 10 IS ACTIVATED CODE#
The original code will work fine whether or not other running processes have spaces in their names. If you are concerned that the program name may have spaces in it then you need to complicate the code very slightly: SETLOCAL EnableExtensionsįOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF NOT %%x = %EXE_% ( The original code apparently had a GOTO in it, which someone in the comments thought uncouth. SETLOCAL EnableExtensionsįOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF NOT %%x = %EXE% ( At the end I could find a fairly simple solution, so I share it. So I added the idea from Matt Lacey's solution, which creates an also avoidable temp file. I like Chaosmaster's solution! But I looked for a solution which does not start another external program (like find.exe or findstr.exe).