您的位置:首页 > 编程语言 > VB

Visual Basic 中判断指定名称的进程是否存在

2014-11-11 08:17 465 查看
简洁版:

Dim Ename
For Each Ename In GetObject("winmgmts:\\.\root\cimv2:win32_process").instances_ '循环进程
If LCase(Ename.name) = LCase("CSTRIKE-ONLINE.EXE") Then MsgBox "请先关掉游戏,否则无法开启外挂!", vbInformation, "提示:"
Next


---------------------------------------------------------------------------

啰嗦版:

Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
On Error GoTo Err
Dim WMI, Obj, 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("notepad.exe") = True Then
MsgBox "已经运行了记事本程序"
Else
MsgBox "记事本程序没有运行"
End If
End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: