VideoHelp Forum




+ Reply to Thread
Results 1 to 3 of 3
  1. Hi cats,

    please consider that I launch a program .exe in a directory, for example c:\myprogram\cat.exe

    I like do a batch that do this:

    if exist a process in background called cat.exe ---> insert in a variable %var% the fullname and path of cat.exe

    In my example %var% = c:\myprogram\cat.exe

    but if - for example - I move cat.exe in e:\myprograms4 (so it become e:\myprograms4\cat.exe) the batch have

    to pick up the new pathname so that %var% = e:\myprograms4\cat.exe

    And if there are present 2 cat.exe processes ---> the batch have to pause and return a error ("Error: there are more of 1 cat.exe process detected!" --> and close all the batch)

    How can I do? thanks
    Quote Quote  
  2. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Its a lot harder than you think, at least for DOS CLI method. You can get the pathsof all that are running by using such as:

    Code:
    wmic process where "name='cat.exe'" get ExecutablePath /FORMAT:LIST
    You can further put these in a text file by using:

    Code:
    wmic process where "name='cat.exe'" get ExecutablePath /FORMAT:LIST > "list.txt"
    Count the lines like so:

    Code:
    findstr /R /N "^" List.txt | find /C ":"
    Now if there are more than 1 line, the easiest would just be a call to 'taskkill' all the processes at once:

    Taskkill /IM cat.exe /F
    SUCCESS: The process "cat.exe" with PID 7472 has been terminated.
    SUCCESS: The process "cat.exe" with PID 6352 has been terminated.
    SUCCESS: The process "cat.exe" with PID 10144 has been terminated.

    http://tweaks.com/windows/39559/kill-processes-from-command-prompt/

    The other method is to have an exe written to do specifically what you wish. Either way is not that quick or easy but it can be done
    Last edited by Budman1; 11th Oct 2016 at 00:34.
    Quote Quote  
  3. Image
    [Attachment 38903 - Click to enlarge]


    mmm nice!! it works, thankss
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!