How to check if a process is running via a batch script

后端 未结 18 2095
一个人的身影
一个人的身影 2020-11-22 07:38

How can I check if an application is running from a batch (well cmd) file?

I need to not launch another instance if a program is already running. (I can\'t change th

18条回答
  •  旧时难觅i
    2020-11-22 07:53

    I used the script provided by Matt (2008-10-02). The only thing I had trouble with was that it wouldn't delete the search.log file. I expect because I had to cd to another location to start my program. I cd'd back to where the BAT file and search.log are, but it still wouldn't delete. So I resolved that by deleting the search.log file first instead of last.

    del search.log
    
    tasklist /FI "IMAGENAME eq myprog.exe" /FO CSV > search.log
    
    FOR /F %%A IN (search.log) DO IF %%-zA EQU 0 GOTO end
    
    cd "C:\Program Files\MyLoc\bin"
    
    myprog.exe myuser mypwd
    
    :end
    

提交回复
热议问题