Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
If there are multiple instances of the batch file running, PID5chars and PID4chars will only find one of them, and you will only know about that instance... Am I missing something? --- What I am trying to do is, upon running a batch file, check if there is an instance of that specific batch file already running. If there is another one running, just quit and let the previously running batch file continue to run. If there is no other one running, just continue to run.
(Part 2) --- It really seems like it should work, but I tried various settings for the "Title" command and "%PROCESS_NAME_TO_COUNT%" and almost got it working but never reliably/repeatedly. And, if 2 instances are started within a short time (some few seconds), "%PROCESS_COUNTER%" is always "=1" for both, so both continue to run.
1) You cover "process_count<2", "process_count=3", and "process_count>3"... What if "process_count=2" ? (Or will that never happen?). 2) You talk about using the "Title" command to set the "WINDOWTITLE", but you don't give an example of what to set the "Title" to, when (where in the code) "Title" should be set, and if/when "Title" should be reset to "Command Prompt". 3) In the "FOR" command you use %PROCESS_NAME_TO_COUNT%, but again, you don't set it before using it (it's UNDEFINED), you only "Reset" it to "NULL" after the "FOR" command completes. (Part 1/2: Continued-->)
@TWiStErRob - I'm sure you know it but to be clear... even with %* you need to use shift to access parameters beyond %9. The advantage of using %* is you can pass the entire ORIGINAL parameter list (including parameters that have been "shifted out") to an external batch or other program, or with a call :label %*, even if you don't know how many parameters are in the list (or if it's more than 9).