|
-
Feb 22nd, 2001, 05:33 PM
#1
Thread Starter
Fanatic Member
Does anyone know of a way of stopping execution of a VB6 program until after a shelled program has been run?
So that if I have something like
Shell "C:\WINDOWS\Desktop\tmp.exe"
Kill "C:\WINDOWS\Desktop\tmp.exe"
I can wait until tmp.exe has stopped running to get rid of it?
-
Feb 23rd, 2001, 05:00 AM
#2
Addicted Member
Start the program using Shell. Wait for it using WaitForSingleObject.
Code:
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = -1&
' Start the indicated program and wait for it
' to finish, hiding while we wait.
Private Sub ShellAndWait(ByVal program_name As String)
Dim process_id As Long
Dim process_handle As Long
' Start the program.
On Error GoTo ShellError
process_id = Shell(program_name, vbNormalFocus)
On Error GoTo 0
' Hide.
Me.Visible = False
DoEvents
' Wait for the program to finish.
' Get the process handle.
process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
If process_handle <> 0 Then
WaitForSingleObject process_handle, INFINITE
CloseHandle process_handle
End If
' Reappear.
Me.Visible = True
Exit Sub
ShellError:
MsgBox "Error starting task " & _
txtProgram.Text & vbCrLf & _
Err.Description
End Sub
Hope this helps.
Shrog
VB6 Ent SP5
Win2000 
-
Feb 23rd, 2001, 07:53 AM
#3
Fanatic Member
-
Feb 23rd, 2001, 08:04 AM
#4
Thread Starter
Fanatic Member
Thanks Shrog & faisalkm - greatly appreciated!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|