English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i have write a program to run several .exe files (around 4 exe files to run) in sequence using shell. however, the application will hang, thus not launching the next exe file. I have to end the non-responding application, so that the next exe will run.

why is this so? what is the disdvantage of using shell?

2007-01-14 15:55:20 · 2 answers · asked by fang 4 in Computers & Internet Programming & Design

i have use shell and wait.. so that the next one will be executed after the previous one is done.
For all the exe file i have, is actually application setup file, so there is only 1 exe for the setup and no others files append to it.
But for 1 of the setup, it contains many subfolders and files.
Everytime, it run the main exe for this setup, the vb application will hang, and the installer for this exe will not appear

2007-01-14 16:19:04 · update #1

2 answers

The shell command runs the first .exe then moves on to the next function. It doesn't automatically wait for the .exe to finish before moving on.
I've forgotten the method/syntax, but you need to find a shell.wait or similar that finishes the first .exe before moving on.

good luck

2007-01-14 16:11:23 · answer #1 · answered by rod 6 · 1 0

Try the following. It doesn't use shell, but creates a process and lets you monitor it. The code below will poll the exe every 200ms. Either it will run or you can set an overall timeout and go on to the next exe. Study below code until you're comfortable knowing what it does before using.

rem various constants
Public Const SYNCHRONIZE = &H100000
Public Const INFINITE = &HFFFFFFFF ' Infinite timeout
Public Const DEBUG_PROCESS = &H1
Public Const DEBUG_ONLY_THIS_PROCESS = &H2
Public Const CREATE_SUSPENDED = &H4
Public Const DETACHED_PROCESS = &H8
Public Const CREATE_NEW_CONSOLE = &H10
Public Const NORMAL_PRIORITY_CLASS = &H20
Public Const IDLE_PRIORITY_CLASS = &H40
Public Const HIGH_PRIORITY_CLASS = &H80
Public Const REALTIME_PRIORITY_CLASS = &H100
Public Const CREATE_NEW_PROCESS_GROUP = &H200
Public Const CREATE_NO_WINDOW = &H8000000
Public Const WAIT_FAILED = -1&
Public Const WAIT_OBJECT_0 = 0
Public Const WAIT_ABANDONED = &H80&
Public Const WAIT_ABANDONED_0 = &H80&
Public Const WAIT_TIMEOUT = &H102&
Public Const STARTF_USESHOWWINDOW = 1
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_NORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10
Public Const SW_FORCEMINIMIZE = 11
Public Const SW_MAX = 11

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

Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Rem various declares
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CreateProcessBynum Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Declare Function ShellExecuteEx Lib "shell32.dll" (lpShexo As SHELLEXECUTEINFO) As Boolean
Declare Function GetProcessId Lib "kernel32.dll" (ByVal hProcess As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Rem here's where we do the work; called with the fully-qualified exe name as parameter
Sub RunIt (exe as string)
Call InitializeSinfo(sinfo)
sinfo.dwFlags = STARTF_USESHOWWINDOW
'sinfo.wShowWindow = SW_HIDE
if CreateProcessBynum(vbNullString, Exe, 0, 0, True, NORMAL_PRIORITY_CLASS, ByVal 0&, vbNullString, sinfo, pinfo) != 0
WaitAndDoEvents pinfo, 200
Else
Exit sub
End If

Sub InitializeSinfo(sinfo As STARTUPINFO)
sinfo.cb = Len(sinfo)
sinfo.lpReserved = vbNullString
sinfo.lpDesktop = vbNullString
sinfo.lpTitle = vbNullString
sinfo.dwFlags = 0
End Sub

Sub WaitAndDoEvents(pinfo As PROCESS_INFORMATION, PollTime As Long)
Dim rv As Long
' Let the process initialize
Call WaitForInputIdle(pinfo.hProcess, INFINITE)
' We don't need the thread handle
Call CloseHandle(pinfo.hThread)
Do
rv = WaitForSingleObject(pinfo.hProcess, PollTime)
If rv <> WAIT_TIMEOUT Then
' No timeout, app is terminated
Exit Do
End If
DoEvents
Loop While True
' Kill the last handle of the process
Call CloseHandle(pinfo.hProcess)
End Sub

2007-01-14 18:17:11 · answer #2 · answered by miket 4 · 1 0

fedest.com, questions and answers