If App.PrevInstance Then MsgBox "程序已经开始运行...", 48 End End If
对不起,没看清楚。看看下面的例子。 Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Function IsRunning(ByVal ProgramID) As Boolean ' 传入进程标识ID Dim hProgram As Long '被检测的程序进程句柄 hProgram = OpenProcess(0, False, ProgramID) If Not hProgram = 0 Then IsRunning = True Else IsRunning = False End If CloseHandle hProgram End Function Sub Form_Click() Dim X Me.Caption = "开始运行" X = Shell("NotePad.EXE", 1) While IsRunning(X) DoEvents Wend Me.Caption = "结束运行" End Sub
MsgBox "程序已经开始运行...", 48
End
End If
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Function IsRunning(ByVal ProgramID) As Boolean ' 传入进程标识ID
Dim hProgram As Long '被检测的程序进程句柄
hProgram = OpenProcess(0, False, ProgramID)
If Not hProgram = 0 Then
IsRunning = True
Else
IsRunning = False
End If
CloseHandle hProgram
End Function Sub Form_Click()
Dim X
Me.Caption = "开始运行"
X = Shell("NotePad.EXE", 1)
While IsRunning(X)
DoEvents
Wend
Me.Caption = "结束运行"
End Sub