How can i verify if a process is already running on powershell?

前端 未结 1 1867
日久生厌
日久生厌 2020-12-20 10:04

i have the following code

Start-Process -windowstyle minimized \"C:/xampp/xampp-control.exe\"

There is a way to know if process is already run

相关标签:
1条回答
  • 2020-12-20 10:18

    One way to do this is to get the process ID of the process (use the -PassThru parameter of Start-Process) and then you can see if the process exists by ID. Example:

    $processId = (Start-Process notepad -PassThru).Id
    if ( Get-Process -Id $processId -ErrorAction SilentlyContinue ) {
       "Process is running"
    }
    
    0 讨论(0)
提交回复
热议问题