But how I can close it?
Efim Shvartsburg a écrit :
>
> I know how to open external program from VBA using
> Shell(pathname[,windowstyle])
> But how I can close it?
You can use API calls to do this. For instance, the following code opens
Winmine.exe (one of my preferred Wingames: 142 seconds at expert level
;-), and then closes it by using TerminateProcess.
Tested only in Win95 :
Declare Function OpenProcess Lib "Kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Declare Function GetExitCodeProcess Lib "Kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Declare Function TerminateProcess Lib "Kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Sub Test()
Dim ProcessHandle As Long
Dim ProcessId As Long
Dim ExitCode As Long
' Launch a new instance of WinMine.exe
ProcessId = Shell("Winmine.exe", vbMinimizedNoFocus)
ProcessHandle = OpenProcess(&H1F0000, 0, ProcessId)
GetExitCodeProcess ProcessHandle, ExitCode
' Close WinMine
MsgBox "Ready to close WinMine?", vbOKOnly
TerminateProcess ProcessHandle, ExitCode
End Sub
HTH,
Laurent
Patrick
______
Laurent Longre wrote in message <36A528DF...@wanadoo.fr>...
Laurent
Patrick Molloy a écrit :