寻找禁止重复调用方案
我用vb调用外部程序1.exe,点击command时shell程序1.exe,这时问题来了,1.exe已经调用出来,可是再点击1.exe又出来一次。有没办法多次点击按钮时,调用的是这个已经打开的1.exe,不要再重新打开。新手,请教大家,不要不理我呀!
给点意见嘛
Public Function CheckExeIsRun(exeName As String) As Boolean '将Pravite 改为 Public (全局) 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("工程1.exe") Then 'IF条件判断语句,判断工程1.exe是否打开 MsgBox "工程1已经打开,您不能重复打开!" '如果已经打开,则弹出提示框,提示您,工程已经打开,不能重复打开。 Else Shell App.Path & "\" & "工程1.exe" '如果没有打开,则打开工程1.exe End If End Sub