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")
'检查进程是否运行,根据进程名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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)