Option Explicit Private Const NORMAL_PRIORITY_CLASS As Long = &H20& Private Const STARTF_USESHOWWINDOW As Long = &H1 Private Const STARTF_USESTDHANDLES As Long = &H100& Private Type SECURITY_ATTRIBUTES nLength As Long lpSecurityDescriptor As Long bInheritHandle As Long End Type Private Type STARTUPINFO cb As Long lpReserved As Long lpDesktop As Long lpTitle As Long 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 ReadFile Lib "kernel32" (ByVal hFile As Long, ByVal lpBuffer As String, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As Any, ByVal nSize As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As Any, lpProcessInformation As Any) As Long Function ShellEx(ByVal PathName As String, Optional ByVal CommandLine As String vbNullString, Optional ByVal WindowStyle As VbAppWinStyle vbMinimizedFocus) As String Dim proc As PROCESS_INFORMATION Dim sa As SECURITY_ATTRIBUTES Dim start As STARTUPINFO Dim sBuffer As String * 256 Dim hReadPipe As Long Dim hWritePipe As Long Dim ret As Long Dim lngBytesRead As Long sa.nLength = Len(sa) sa.bInheritHandle = True If (CreatePipe(hReadPipe, hWritePipe, sa, 0) = 0) Then MsgBox "CreatePipe failed. Error: " & Err.LastDllError Exit Function End If start.cb = Len(start) start.hStdError = hWritePipe start.hStdOutput = hWritePipe start.wShowWindow = WindowStyle start.dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW If (CreateProcessA(PathName, CommandLine, sa, sa, True, NORMAL_PRIORITY_CLASS, 0, 0, start, proc) = 0) Then MsgBox "CreateProcess failed. Error: " & Err.LastDllError Exit Function End If CloseHandle hWritePipe Do ret = ReadFile(hReadPipe, sBuffer, 256, lngBytesRead, 0&) ShellEx = ShellEx & Left$(sBuffer, lngBytesRead) Loop While ret CloseHandle proc.hProcess CloseHandle proc.hThread CloseHandle hReadPipe End Function Private Sub Command1_Click() MsgBox ShellEx("c:\windows\system32\netstat.exe") End Sub
E.B.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionE.B.