
How to test if PID is used
Use the following routine. It waits till the process is complete and the
continues. Pass your shell command to
Runshell routine. eg. RunShell("c:\readme.txt"). Hope this helps.
Nilesh Hejib
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STATUS_PENDING = &H103&
Private Sub RunShell(strCmdline As String)
Dim hProcess As Long
Dim ProcessId As Long
Dim exitCode As Long
ProcessId = Shell(cmdline, vbHide)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
Do
Call GetExitCodeProcess(hProcess, exitCode)
DoEvents
Loop While exitCode = STATUS_PENDING
Call CloseHandle(hProcess)
End Sub
Quote:
> Hi all
> I am using the shell function in VB 5.0 to start another program,
> which is ftp, however shell returns before the program terminates
> and it returns the process id of the program started.
> How can I use this process id to cause my program to wait untill
> the process started by shell has terminated and then my program
> is to continue.
> ----------------------------------------------------------------------------
> ---
> Edward Mifsud Bureau of Meteorology
> Melbourne vic 3000
> Tel: 03 9669 4118 AUSTRALIA
> Fax: 03 96694128
> ----------------------------------------------------------------------------
> --
The contents of this message express only the sender's opinion.
This message does not necessarily reflect the policy or views of
my employer, Merck & Co., Inc. All responsibility for the statements
made in this Usenet posting resides solely and completely with the
sender.