|
-
Oct 1st, 2001, 06:21 AM
#8
Thread Starter
New Member
Folks - thanks for your help.
In my case I'm calling something synchronously (i.e. control passes to that process) so I'm not multi-threading or anything complicated - in fact the user is going to do a spreadsheet operation as part of a "workflow" script. But don't let me cramp your style as the issues of multi-threading are also interesting of course.
I'm going to use something based on the following code.
Incidentally, the WIN API viewer didn't give the values for the enumerated dwCreationFlags and so I found out some sample code by seaching on www.google.com (looking for CREATESEPARATE_WOW_VDM =).
In this noddy project there is one command button called "Run".
Obviously the naming standards etc leave something to be desired.
In the bas module:
Option Explicit
Public 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
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Const NORMAL_PRIORITY_CLASS = &H20
Public Const INFINITE = &HFFFF
Public Const STARTF_FORCEOFFFEEDBACK = &H80
Public Const STARTF_FORCEONFEEDBACK = &H40
Public Const STARTF_RUNFULLSCREEN = &H20
Public Const STARTF_USECOUNTCHARS = &H8
Public Const STARTF_USEFILLATTRIBUTE = &H10
Public Const STARTF_USEPOSITION = &H4
Public Const STARTF_USESHOWWINDOW = &H1
Public Const STARTF_USESIZE = &H2
Public Const STARTF_USESTDHANDLES = &H100
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 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_PARENTCLOSING = 1
Public Const SW_OTHERZOOM = 2
Public Const SW_PARENTOPENING = 3
Public Const SW_OTHERUNZOOM = 4
Public Const SW_HIDE = 0
Public Const SW_NORMAL = 1
Public Const SW_MAXIMIZE = 3
Public Const SW_MAX = 10
Public Const SW_SCROLLCHILDREN = &H1
Public Const SW_INVALIDATE = &H2
Public Const SW_ERASE = &H4
Public Const CREATE_SEPARATE_WOW_VDM = &H800
Public Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" _
(ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As Any, _
lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, _
lpExitCode As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
In the main code:
Option Explicit
Private Sub cmdRun_Click()
Dim processInfo As PROCESS_INFORMATION
Dim startInfo As STARTUPINFO
Dim lpProcAttr As SECURITY_ATTRIBUTES
Dim lpThrdAttr As SECURITY_ATTRIBUTES
Dim lSuccess As Long
Dim sNull As String
Dim lRetVal As Long
lpProcAttr.bInheritHandle = 0
lpProcAttr.lpSecurityDescriptor = 0
lpProcAttr.nLength = Len(lpProcAttr)
lpThrdAttr.bInheritHandle = 0
lpThrdAttr.lpSecurityDescriptor = 0
lpThrdAttr.nLength = Len(lpThrdAttr)
startInfo.cb = Len(startInfo)
startInfo.dwFlags = STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW
startInfo.wShowWindow = SW_SHOWNORMAL
startInfo.lpDesktop = ""
startInfo.cbReserved2 = 0
startInfo.lpReserved = 0
startInfo.lpTitle = ""
startInfo.lpReserved2 = 0
lSuccess = CreateProcess(sNull, "Q:\LOTSUITE\123R5W\PROGRAMS\123W.EXE", lpProcAttr, lpThrdAttr, _
vbNull, CREATE_SEPARATE_WOW_VDM, ByVal 0&, sNull, startInfo, processInfo)
If lSuccess = 0 Then
MsgBox "failed"
Else
MsgBox "Launched"
lRetVal = TerminateProcess(processInfo.hProcess, 0&)
lRetVal = CloseHandle(processInfo.hThread)
lRetVal = CloseHandle(processInfo.hProcess)
MsgBox "teminated"
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|