|
-
Aug 4th, 2000, 01:10 AM
#1
Thread Starter
Hyperactive Member
I know someone out there knows this, because I've seen it myself somewhere...
How can I detect when a program I've shelled with ShellExecute has finished?
I need something that loops, if possible, so that I can keep it within a single form's sub to ease things along. Something along the lines of:
Code:
Do While (StillExecuting)
DoEvents
Loop
So that I can put in the code to execute after it's finished immediately after the loop.
Thanks in advance.
-
Aug 4th, 2000, 01:29 AM
#2
Hyperactive Member
Try taking a look at this (I've never used it, but heard it works):
http://www.planet-source-code.com/vb...txtCodeId=1102
-
Aug 4th, 2000, 01:31 AM
#3
Here you go:
Code:
Public 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
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Public Declare Function WaitForSingleObject _
Lib "kernel32" ( _
ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Public Declare Function CreateProcess _
Lib "kernel32" Alias "CreateProcessA" ( _
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
Public Declare Function CloseHandle _
Lib "kernel32" ( _
ByVal hObject As Long) As Long
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
Public Const STARTF_USESHOWWINDOW = &H1
Public Sub ShellAndWait(sCmd As String, Optional WindowStyle As VbAppWinStyle = vbNormalFocus)
Dim udtStart As STARTUPINFO
Dim udtProc As PROCESS_INFORMATION
udtStart.cb = Len(udtStart)
udtStart.dwFlags = STARTF_USESHOWWINDOW
udtStart.wShowWindow = WindowStyle
CreateProcess 0&, sCmd, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, udtStart, udtProc
WaitForSingleObject udtProc.hProcess, INFINITE
CloseHandle udtProc.hProcess
End Sub
Just call the ShellAndWait sub and pass the command line as the first argument and optionally the state for the window.
Code:
ShellAndWait "Notepad.exe", vbMaximizedFocus
If you want to call a DOS application please do so by calling the COMMAND.COM or CMD.EXE with the /C parameter for the application to "self close".
Code:
Dim sCmd As String
sCmd = Environ("COMSPEC") & " /C "
sCmd = sCmd & "c:\MyBatFile.Bat"
ShellAndWait sCmd, vbHide
Good luck!
-
Aug 4th, 2000, 02:06 AM
#4
Thread Starter
Hyperactive Member
Thanks, Joacim, your seemed real good but I got an error while running it.
I ended up using reeset's, which turned out to work just fine.
Thanks both
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
|