How to Correctly Check if a Process is running and Stop it

后端 未结 4 922
遇见更好的自我
遇见更好的自我 2021-01-30 10:26

What is the correct way of determining if a process is running, for example FireFox, and stopping it?

I did some looking around and the best way I found was this:

<
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 10:52

    If you don't need to display exact result "running" / "not runnuning", you could simply:

    ps notepad -ErrorAction SilentlyContinue | kill -PassThru
    

    If the process was not running, you'll get no results. If it was running, you'll receive get-process output, and the process will be stopped.

提交回复
热议问题