‘ Source in der Form mit einem Command-Button
Option Explicit
Private Sub Command1_Click()
Dim I As Long
Dim ret As Long
Dim hReadPipe1 As Long ' STDOUT
Dim hWritePipe1 As Long ' STDOUT
Dim hReadPipe2 As Long ' STDERR
Dim hWritePipe2 As Long ' STDERR
Dim hReadPipe3 As Long ' STDIN
Dim hWritePipe3 As Long ' STDIN
Dim bytewritten As Long
Dim cmdline As String
Dim StuffToWrite As String
Dim start As STARTUPINFO
Dim proc As PROCESS_INFORMATION
Dim sa As SECURITY_ATTRIBUTES
sa.nLength = Len(sa)
sa.bInheritHandle = True
sa.lpSecurityDescriptor = 0&
' A pipe of redirection of STDOUT
ret = CreatePipe(hReadPipe1, hWritePipe1, sa, 0&)
If ret = 0 Then MsgBox "Konnte Pipe STDOUT nicht öffnen: " & Err.LastDllError
' A pipe of redirection of STDERR
ret = CreatePipe(hReadPipe2, hWritePipe2, sa, 0&)
If ret = 0 Then MsgBox "Konnte Pipe STDERR nicht öffnen: " & Err.LastDllError
' A pipe of redirection of STDIN
ret = CreatePipe(hReadPipe3, hWritePipe3, sa, 0&)
If ret = 0 Then MsgBox "Konnte Pipe STDIN nicht öffnen: " & Err.LastDllError
start.cb = Len(start)
start.dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
start.hStdOutput = hWritePipe1
start.hStdError = hWritePipe2
start.hStdInput = hReadPipe3
start.wShowWindow = SW_NORMAL
' Programmaufruf
cmdline$ = "command.com"
ret = CreateProcess(0&, cmdline$, 0&, 0&, True, NORMAL_PRIORITY_CLASS, 0&, _
0&, start, proc)
If ret = 0 Then
MsgBox "Anwendung kann nicht gestartet werden: " & Err.LastDllError, _
vbCritical
Else
MsgBox "Fremdanwendung gestartet, Handle = " & ret
End If
' Send it.
StuffToWrite = "start notepad\n"
ret = WriteFile(hWritePipe3, StuffToWrite, Len(StuffToWrite), bytewritten, _
CLng(0))
If ret = 0 Then
MsgBox "Anwendung wurde nicht beschrieben: " & Err.LastDllError
Else
MsgBox "Anzahl übergebene Zeichen: " & bytewritten
End If
StuffToWrite = "start exit\n"
ret = WriteFile(hWritePipe3, StuffToWrite, Len(StuffToWrite), bytewritten, _
CLng(0))
If ret = 0 Then
MsgBox "Anwendung wurde nicht beschrieben: " & Err.LastDllError
Else
MsgBox "Anzahl übergebene Zeichen: " & bytewritten
End If
Do While WaitForSingleObject(proc.hProcess, 10) = WAIT_TIMEOUT
DoEvents
Loop
MsgBox "Fremdanwendung, mit dem Handle : " & proc.hProcess & " beendet !", , _
"Hinweis"
' Ungebrauchte Pipe's schließen
CloseHandle hWritePipe1
CloseHandle hWritePipe2
CloseHandle hReadPipe3
CloseHandle hReadPipe1
CloseHandle hReadPipe2
CloseHandle hWritePipe3
End Sub Rückgabewert (bytewritten) ist gefüllt, aber es erfolgt keine Ausgabe. (Start Notepad)
Wer kann helfen? Was ist falsch und verhindert, das es läuft, wie unter C++? Kann man die Übergabe irgendwie sichtbar machen?
Gruß und Dank
BasTler |