:confused: :confused: how do i "shell/start" an app and not let my program continue untill the app has finished?:confused: :confused:
Printable View
:confused: :confused: how do i "shell/start" an app and not let my program continue untill the app has finished?:confused: :confused:
A few weeks ago I've had the same problem. I had found a tip on this site, I'll see if I can find it again.
Till then.
i assume i get the application id of the program i just ran, and wait for that id to dissapear, problem is, i dont know where to start.:rolleyes:
Write a separate module:
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
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
As Long) As Long
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
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Const STARTF_USESHOWWINDOW = &H1
Public Enum enSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum
Public Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
'Initialize the STARTUPINFO structure:
start.cb = Len(start)
'start.dwFlags = STARTF_USESHOWWINDOW
'start.wShowWindow = SW_MAXIMIZE
'Start the shelled application:
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
'Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub
and to start your programm:
Call ExecCmd(your_program_name)
I couldn't find the article this fast, but I copied the code
good luck, if you have any questions, just ask me.
thanks, i'll give it a go
I have tried the previous code snippet and had no luck with it. I am looking for something myself
When u start an app, it goes to the top of the Zorder! How about you obtain the apps name thru the GetWindowText API call, then run a timer every 2.5 secs or so and check if it is still running! if it is, the timer will keep goin until the app is closed. then include some code to get ur program to resume where it left off! sounds complex, it is! but i have done it be4, unfortunately i lost the code when i formatted! :rolleyes:
Sarlacc,
you're right about that. The problem I faced with this solutions was I had to close my form in order to make the new one appear. :eek:
So I couln't use a timer. Another workaround for this problem was to use the system-time and make the check with that one. :D
But the code I provided worked fine for me.
:)
i have/am using the code and it is doing everything that i need it to.
it is only being used to run some batch files.
I am attempting to perform an unattended install of a remote PC from a CD. I need my VB app to script all needed software installs silently and in the background. However, I have been unable to accomplish the small feat of waiting the for the shelled process to complete prior to continuing on with the next step. If anyone has any suggestions or can fix the above mentioned code snippett it would be greatly appreciated.
Thanks
Can you describe your problem with the code I provided? Do you get an error, is the code running but doesn't perform the action requested, where does the problem appear etc. ?
There really isn't anything to report. When I use the code A) nothing happens B) It can't create a new WOW session. I did a little research on my own and found that you need to specfiy the constant 'CREATE_SEPARATE_WOW' and adjust the security attributes. However I have been unsuccessful. It appears some the application setups that I am attempting to run are 16bit and this function wont' run them.