This might not be exactly what you mean, but maybe it will provide you with some ideas to solve your problem.
I made a function ExecCommand to execute a program and my application needed to wait until the program was done. Also it liked it not to be visible (it was a program called 'wmaencoder.exe' and I used it to convert wav to wma audio).
Anyway, the code I used:
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
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
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 Const HIGH_PRIORITY_CLASS As Long = &H80
Private Const NORMAL_PRIORITY_CLASS As Long = &H20&
Private Const INFINITE As Long = -1
Private Const SW_HIDE = 0
Private Const SWP_HIDEWINDOW = &H80
Private Const SW_MINIMIZE = 6
Private Const STARTF_USESHOWWINDOW = &H1
Public Sub ExecCommand(CmdLine As String)
Dim loProc As PROCESS_INFORMATION
Dim loStart As STARTUPINFO
Dim liRetval As Long
loStart.cb = Len(loStart)
loStart.dwFlags = STARTF_USESHOWWINDOW
'Use window properties (in this case, hide the window)
loStart.wShowWindow = SW_HIDE
'Start proces
liRetval = CreateProcessA(0, CmdLine, 0, 0, 1, NORMAL_PRIORITY_CLASS, 0, 0, loStart, loProc)
'Wait until process ended
liRetval = WaitForSingleObject(loProc.hProcess, INFINITE)
'Close process handle
liRetval = CloseHandle(loProc.hProcess)
End Sub
Usage, for example:
ExecCommand "c:\tektips.exe -i c:\temp\tek.txt"
(it's pretty much the same as the Shell-command in vb, but that one doesn't wait until the process has ended)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.