VB.NET怎样判断一个应用程序是否在运行?

xwylpsy 2009-05-21 09:15:43
VB.NET怎样判断一个应用程序是否在运行?
比如:怎样判断是否打开了IE浏览器?
...全文
1197 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lonelymoon9527 2011-08-31
  • 打赏
  • 举报
回复
模块中添加以下代码:

'检测指定进程是否运行
Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
On Error GoTo Err
Dim WMI
Dim Obj
Dim Objs
CheckApplicationIsRun = False
WMI = GetObject("WinMgmts:")
Objs = WMI.InstancesOf("Win32_Process")
For Each Obj In Objs
If InStr(UCase(szExeFileName), UCase(Obj.Description)) <> 0 Then
CheckApplicationIsRun = True
If Not Objs Is Nothing Then Objs = Nothing
If Not WMI Is Nothing Then WMI = Nothing
Exit Function
End If
Next
If Not Objs Is Nothing Then Objs = Nothing
If Not WMI Is Nothing Then WMI = Nothing
Exit Function
Err:
If Not Objs Is Nothing Then Objs = Nothing
If Not WMI Is Nothing Then WMI = Nothing
End Function

========================================
窗体按钮点击的事件:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (CheckApplicationIsRun("123.exe")) Then '123.exe为判断的程序名,修改即可
MessageBox.Show("已经运行")
Else
MessageBox.Show("没有运行")
End If
End Sub
wuxing1129 2009-05-22
  • 打赏
  • 举报
回复
楼上正解。检索每个进程名!
之前还看到另外一种办法,等我找到帖出
my84211 2009-05-22
  • 打赏
  • 举报
回复
Dim pro As Process
For Each pro In Process.GetProcesses
If pro.ProcessName = "进程名称" Then
you can Do sth here
End If
Next
xwylpsy 2009-05-22
  • 打赏
  • 举报
回复
是感谢大家!问题解决了
xwylpsy 2009-05-22
  • 打赏
  • 举报
回复
先谢谢大家!!我试一下
xwylpsy 2009-05-21
  • 打赏
  • 举报
回复
能不能说清楚点!!谢谢你!
a854468521 2009-05-21
  • 打赏
  • 举报
回复
For Each Pro As Process In Process.GetProcesses '获得目前运行的进程
'判断已经运行的进程。
Next

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧