如何验证进程是否已在 powershell 上运行? [英] How can i verify if a process is already running on powershell?

查看:121
本文介绍了如何验证进程是否已在 powershell 上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

Start-Process -windowstyle 最小化C:/xampp/xampp-control.exe"

有没有办法知道进程是否已经在运行?

There is a way to know if process is already running?

推荐答案

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

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"
}

这篇关于如何验证进程是否已在 powershell 上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆