如何用VB编写一个查询进程是否在运行的程序,要简洁的,最好详细代码
3个回答
展开全部
'这个简单
Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
On Error GoTo Err
Dim WMI
Dim Obj
Dim Objs
CheckApplicationIsRun = False
Set WMI = GetObject("WinMgmts:")
Set 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 Set Objs = Nothing
If Not WMI Is Nothing Then Set WMI = Nothing
Exit Function
End If
Next
If Not Objs Is Nothing Then Set Objs = Nothing
If Not WMI Is Nothing Then Set WMI = Nothing
Exit Function
Err:
If Not Objs Is Nothing Then Set Objs = Nothing
If Not WMI Is Nothing Then Set WMI = Nothing
End Function
Private Sub Command1_Click()
If CheckApplicationIsRun("qq.exe") = True Then
MsgBox "该进程已经存在!!", , "提示"
Else
MsgBox "该进程不存在!!", , "提示"
End If
'采纳吧
End Sub
Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
On Error GoTo Err
Dim WMI
Dim Obj
Dim Objs
CheckApplicationIsRun = False
Set WMI = GetObject("WinMgmts:")
Set 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 Set Objs = Nothing
If Not WMI Is Nothing Then Set WMI = Nothing
Exit Function
End If
Next
If Not Objs Is Nothing Then Set Objs = Nothing
If Not WMI Is Nothing Then Set WMI = Nothing
Exit Function
Err:
If Not Objs Is Nothing Then Set Objs = Nothing
If Not WMI Is Nothing Then Set WMI = Nothing
End Function
Private Sub Command1_Click()
If CheckApplicationIsRun("qq.exe") = True Then
MsgBox "该进程已经存在!!", , "提示"
Else
MsgBox "该进程不存在!!", , "提示"
End If
'采纳吧
End Sub
展开全部
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim hwd As Long
Private Sub Timer1_Timer()
hwd = FindWindow(vbNullString, "植物大战僵尸")
If hwd <> 0 Then
Label1.Caption = "游戏【植物大战僵尸】正在运行!": Label1.ForeColor = vbRed: Label1.FontSize = 16
End If
If hwd = 0 Then
Label1.Caption = "游戏【植物大战僵尸】没有运行!": Label1.ForeColor = vbRed: Label1.FontSize = 16
End If
End Sub
简洁的、、、、、、、、、、、
Dim hwd As Long
Private Sub Timer1_Timer()
hwd = FindWindow(vbNullString, "植物大战僵尸")
If hwd <> 0 Then
Label1.Caption = "游戏【植物大战僵尸】正在运行!": Label1.ForeColor = vbRed: Label1.FontSize = 16
End If
If hwd = 0 Then
Label1.Caption = "游戏【植物大战僵尸】没有运行!": Label1.ForeColor = vbRed: Label1.FontSize = 16
End If
End Sub
简洁的、、、、、、、、、、、
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个很简单 不给分懒得给你写
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询