如何用vb编写一个查询进程是否在运行的程序,要简洁的,最好详细代...
发布网友
发布时间:2024-09-28 07:07
我来回答
共3个回答
热心网友
时间:2024-09-28 09:05
'这个简单
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
热心网友
时间:2024-09-28 09:03
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
简洁的、、、、、、、、、、、
热心网友
时间:2024-09-28 09:02
这个很简单 不给分懒得给你写