Private Function CheckExeIsRun(exeName As String) As Boolean
On Error GoTo Err
Dim WMI
Dim Obj
Dim Objs
CheckExeIsRun = False
Set WMI = GetObject("WinMgmts:")
Set Objs = WMI.InstancesOf("Win32_Process")
For Each Obj In Objs
If (InStr(UCase(exeName), UCase(Obj.Description)) <>0) Then
CheckExeIsRun = 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 CheckExeIsRun("A.exe") 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
Private
Sub
Command5_Click()
Dim
lHwnd
As
Long
lHwnd
=
FindWindow(vbNullString,
"程序的Title或Caption")
If
lHwnd
<>
0
Then
MsgBox
"程序正告启在运行!"
End
If
End
Sub
向它发送指兄好令:
AppActivate
"程序的Title或Caption"
SendKeys
"指令"
要启动程序:
Call
Shell("完整路径和程序名称.exe")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)