Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CreateProcess in VB

0 views
Skip to first unread message

Conax

unread,
Feb 23, 1999, 3:00:00 AM2/23/99
to
Hi,
I am trying to use the CreateProcess function (of Win32 APIs) in a VB
project. Does any body has an example?

Thank you.
Conax

Gray

unread,
Feb 24, 1999, 3:00:00 AM2/24/99
to
'---------------------------------------------------------------------------
----------------------------

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

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

'---------------------------------------------------------------------------
----------------------------

Declare Function CreateProcess 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 lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO,
lpProcessInformation As PROCESS_INFORMATION) As Long

Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long,
ByVal dwMilliSeconds As Long) As Long

'---------------------------------------------------------------------------
----------------------------

Function ExecuteApplication(ByVal strApplication As String, Optional ByVal
strCommandLine As String, Optional ByVal bWait As Boolean = True) As Long

Dim udtStartup As STARTUPINFO
Dim udtProcess As PROCESS_INFORMATION
Dim lPID As Long

lPID = CreateProcess(strApplication, strCommandLine, 0, 0, False, 0,
ByVal 0&, vbNullString, udtStartup, udtProcess)
If lPID <> 0 Then

CloseHandle udtProcess.hThread

If bWait Then
WaitForInputIdle udtProcess.hProcess, &HFFFF
End If

End If

ExecuteApplication = lPID

End Function

'---------------------------------------------------------------------------
----------------------------

To use:

ExecuteApplication "myapp.exe"

Conax <con...@olympic.co.nz> wrote in message
news:01be5f8a$1da83100$8664a8c0@conwaynew...

0 new messages