Batch program to to check if process exists

前端 未结 5 1991
一整个雨季
一整个雨季 2020-12-02 14:55

I want a batch program, which will check if the process notepad.exe exists.

if notepad.exe exists, it will end the process

5条回答
  •  情歌与酒
    2020-12-02 15:15

    That's why it's not working because you code something that is not right, that's why it always exit and the script executer will read it as not operable batch file that prevent it to exit and stop so it must be

    tasklist /fi "IMAGENAME eq Notepad.exe" 2>NUL | find /I /N "Notepad.exe">NUL
    if "%ERRORLEVEL%"=="0" (
    msg * Program is running
    goto Exit
    )
    else if "%ERRORLEVEL%"=="1" (
    msg * Program is not running
    goto Exit
    )
    

    rather than

    @echo off
    tasklist /fi "imagename eq notepad.exe" > nul
    if errorlevel 1 taskkill /f /im "notepad.exe"
    exit
    

提交回复
热议问题