Website Design United States, Website Design California, Website Designing United States, Website Designing California

Shell a process and wait for it to finish - Visual Basic 6

Option Explicit
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 '

Private Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As String, 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 Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

'----------------------------------------------------------------------
' Name: ExecCmd
' Author: George Lissauer
' Created: Saturday, June 20,1998 @ 5:20:06 pm (Vers: 1.0.0000)
'
' Description: Shell an application and wait for it to finish
' Inputs: sCmdLine - Application Start Command
' Results: Returns when the application finishes.
'----------------------------------------------------------------------

Public Sub ExecCmd(sCmdLine As String)
Dim lR As Long 'Return
Dim uProc As PROCESS_INFORMATION
Dim uStart As STARTUPINFO

' Initialize the STARTUPINFO structure:
uStart.cb = Len(uStart) '

' Start the shelled application:
lR = CreateProcessA(sCmdLine, vbNullString, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, uStart, uProc) '

' Wait for the shelled application to finish:
lR = WaitForSingleObject(uProc.hProcess, INFINITE) '
lR = CloseHandle(uProc.hProcess) '
End Sub

Public Sub ShellAndWait()
ExecCmd txtLaunch.Text 'Launch and wait for exe
End Sub

Public Sub ShellUsingVB()
Shell txtLaunch.Text, vbMinimizedNoFocus 'Launch exe, minimized so user can see both boxes
End Sub

WEB DESIGN INDIA
42 B Malviya Nagar , New Delhi-110017

Skype: manmeetsi
Email: support.webdesignindia@gmail.com
Tel: 91-011-40502005, 9810067295

 















 


© 2008-2009 dotnet4all.com