vb 检测某个进程是否运行

vb 检测某个进程是否运行,第1张

'检查祥判进程是否运行,根据衡宴猛进程名

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")


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12445816.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存