|
-
Dec 21st, 2002, 05:40 PM
#1
Thread Starter
Frenzied Member
Wait till Shell operation is complete
Hi,
I am shelling to another application to process a file
Once this processing is complete (typically a few minutes), I need to shell out to another application.
Currently, I have the two shell commands one after another, but they both get called at the same time.
How do you determine when the first shell operation is complete before staring another one??????
Thanx for any suggestions!
-
Dec 21st, 2002, 07:23 PM
#2
Hyperactive Member
Use this in a module
VB Code:
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadID As Long
End Type
Const NORMAL_PRIORITY_CLASS = &H20
Const IDLE_PRIORITY_CLASS = &H40
Const HIGH_PRIORITY_CLASS = &H80
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As _
String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, lpStartupInfo As _
STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) _
As Long
Public Sub ShellNWait(CommandLine As String, Optional WaitForMilliseconds As Long = -1&, Optional Priority As Long = NORMAL_PRIORITY_CLASS)
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim lRet As Long
On Error Resume Next
'Initialize the STARTUPINFO structure:
Start.cb = Len(Start)
'Start the shelled application:
lRet = CreateProcessA(0&, CommandLine, 0&, 0&, 1&, _
Priority, 0&, 0&, Start, proc)
'Wait for the shelled application to finish:
'use -1 to specify no "timeout" length.
lRet = WaitForSingleObject(proc.hProcess, WaitForMilliseconds)
lRet = CloseHandle(proc.hProcess)
End Sub
And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.
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
|