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

后端 未结 18 2358
一个人的身影
一个人的身影 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条回答
  •  甜味超标
    2020-11-22 08:08

    The suggestion of npocmaka to use QPROCESS instead of TASKLIST is great but, its answer is so big and complex that I feel obligated to post a quite simplified version of it which, I guess, will solve the problem of most non-advanced users:

    QPROCESS "myprocess.exe">NUL
    IF %ERRORLEVEL% EQU 0 ECHO "Process running"
    

    The code above was tested in Windows 7, with a user with administrator rigths.

提交回复
热议问题