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 FunctionPrivate Sub Command1_Click()
If CheckApplicationIsRun("Main.exe") = True Then
SendKeys "%{TAB}"
Else
Shell "C:\Main.exe"
End If
End Sub能够判断进程存不存在,但是为什么他不能执行sendkeys呀。
(因为我只是想让main.exe进程存在的时候重新获得焦点。类似于alt+tab。)
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 FunctionPrivate Sub Command1_Click()
If CheckApplicationIsRun("Main.exe") = True Then
SendKeys "%{TAB}"
Else
Shell "C:\Main.exe"
End If
End Sub能够判断进程存不存在,但是为什么他不能执行sendkeys呀。
(因为我只是想让main.exe进程存在的时候重新获得焦点。类似于alt+tab。)
解决方案 »
- 100分求一VB函数:返回指定时间段内所有的周、月、季度?
- SelectedRows=0 ?是为什啊
- VB类编程问题!关于Get和Let
- vb程序,动态执行vb代码的问题
- 键盘上的左右“win键”和“菜单键”的virtual-key code 是多少?
- 能否用MSHFlexGrid控件显示多层树形结构
- 如何控制菜单显示以供不同用户使用,以限制功能?(在线等待)
- vb间的进程通讯问题
- 我要开发一流程图管理软件,我自己定义了一个类(即流程图上的节点),可在窗口画出,但我不知道如何将图保存。(不要存成图片格式)
- 我使用2个picturebox控件,和一个vscroll控件,我怎样让滑块滚动的得快一些,并且滑块大一些
- vsFlexGrid控件可以用在delphi中吗
- 串口数据处理写进数据库的问题,请高手赐教!
msgbox "执行到此"SendKeys "%{TAB}" '看是否执行到这里
Else
Shell "C:\Main.exe"
End If
End Sub