如何验证某个进程是否已在powershell上运行?

如何验证某个进程是否已在powershell上运行?,powershell,prompt,Powershell,Prompt,我有以下代码 启动进程-windowstyle最小化“C:/xampp/xampp control.exe” 有一种方法可以知道进程是否已经在运行?一种方法是获取进程的进程ID(使用启动进程的-PassThru参数),然后通过ID查看进程是否存在。示例: $processId = (Start-Process notepad -PassThru).Id if ( Get-Process -Id $processId -ErrorAction SilentlyContinue ) { "Pr

我有以下代码

启动进程-windowstyle最小化“C:/xampp/xampp control.exe”


有一种方法可以知道进程是否已经在运行?

一种方法是获取进程的进程ID(使用
启动进程的
-PassThru
参数),然后通过ID查看进程是否存在。示例:

$processId = (Start-Process notepad -PassThru).Id
if ( Get-Process -Id $processId -ErrorAction SilentlyContinue ) {
   "Process is running"
}

一种方法是获取流程的流程ID(使用
启动流程
-PassThru
参数),然后您可以通过ID查看流程是否存在。示例:

$processId = (Start-Process notepad -PassThru).Id
if ( Get-Process -Id $processId -ErrorAction SilentlyContinue ) {
   "Process is running"
}