VB的Shell函数返回的程序ID有什么用?该怎么用?
如题。同时想问一下,我用Shell函数返回的程序ID,用GetExitCodeProcess函数是不是可以取回这个进程的退出代码?怎么通过代码知道进程已经结束?
[解决办法]
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredaccess&, ByVal bInherithandle&, ByVal dwProcessid&) As LongPrivate Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpexitcode As Long) As LongConst STILL_ACTIVE = &H103Const PROCESS_QUERY_INFORMATION = &H400Private Sub ShellWait(strCode As String) Dim hShell As Long Dim hProc As Long Dim lExit As Long hShell = Shell(strCode, 1) hProc = OpenProcess(PROCESS_QUERY_INFORMATION, False, hShell) Do GetExitCodeProcess hProc, lExit DoEvents Loop While lExit = STILL_ACTIVEEnd SubPrivate Sub Command1_Click() ShellWait "notepad" MsgBox "ok"End Sub
[解决办法]
返回的PID<=0时 调用失败
[解决办法]
返回的是进程的PID,通过 PID,你可以挂起,结束这个进程