![]() |
Access Validation bei CreateProcess
Ich habe bei CreateProcess eine Acess Validation
Delphi-Quellcode:
Diese Funktion habe ich aus dem Delphi Forum
// Konsolen-kommando ausführen und Ergebnis/Fehler zurückliefern
function ExecConsoleCommand(const ACommand: String; var AOutput, AErrors: String; var AExitCode: Cardinal): Boolean; var StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation; SecurityAttr: TSecurityAttributes; PipeOutputRead, PipeOutputWrite, PipeErrorsRead, PipeErrorsWrite: THandle; // Pipe in einen String auslesen procedure ReadPipeToString(const hPipe: THandle; var Result: String); var AvailableBytes, ReadBytes: Cardinal; Buffer: String; begin PeekNamedPipe(hPipe, NIL, 0, NIL, @AvailableBytes, NIL); // wieviel ist da while (AvailableBytes > 0) do begin // überhaupt was da? SetLength(Buffer,AvailableBytes); // Buffer if ReadFile(hPipe,PChar(Buffer)^,AvailableBytes,ReadBytes,NIL) then // Lesen hat geklappt if (ReadBytes > 0) then begin // Daten angekommen? SetLength(Buffer,ReadBytes); // falls weniger kam, als da ist (warum auch immer) Result := Result +Buffer; // an den Ergebnis-String end; PeekNamedPipe(hPipe, NIL, 0, NIL, @AvailableBytes, NIL); // noch was da? end; end; begin AOutput := ''; AErrors := ''; // Win-API-Strukturen initialisieren/füllen FillChar(ProcessInfo,SizeOf(TProcessInformation),0); FillChar(SecurityAttr,SizeOf(TSecurityAttributes),0); SecurityAttr.nLength := SizeOf(SecurityAttr); SecurityAttr.bInheritHandle := TRUE; SecurityAttr.lpSecurityDescriptor := NIL; CreatePipe(PipeOutputRead,PipeOutputWrite,@SecurityAttr,0); CreatePipe(PipeErrorsRead,PipeErrorsWrite,@SecurityAttr,0); FillChar(StartupInfo,SizeOf(TStartupInfo),0); StartupInfo.cb := SizeOf(StartupInfo); StartupInfo.hStdInput := 0; StartupInfo.hStdOutput := PipeOutputWrite; StartupInfo.hStdError := PipeErrorsWrite; StartupInfo.wShowWindow := SW_HIDE; StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; // http://msdn2.microsoft.com/en-us/library/ms682425.aspx Result := CreateProcess(NIL,PChar(ACommand),NIL,NIL,TRUE, <--Hier CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,NIL,StartupInfo,ProcessInfo); if Result then begin // Prozess erfolgreich gestartet? repeat GetExitCodeProcess(ProcessInfo.hProcess,AExitCode); // http://msdn2.microsoft.com/en-us/library/ms683189.aspx ReadPipeToString(PipeOutputRead,AOutput); // Ausgaben lesen ReadPipeToString(PipeErrorsRead,AErrors); // Fehler lesen if (AExitCode = STILL_ACTIVE) then Sleep(1); until (AExitCode <> STILL_ACTIVE); // bis der Prozess sich selbst beendet hat CloseHandle(ProcessInfo.hThread); // Handles freigeben CloseHandle(ProcessInfo.hProcess); end; CloseHandle(PipeOutputWrite); // Pipes schließen CloseHandle(PipeErrorsWrite); CloseHandle(PipeOutputRead); CloseHandle(PipeErrorsRead); end; ![]() hat einer eine Idee was da Falsch ist. Ich nutze Win 7 Pro x64 und Delphi XE2 SP3 Zielplattform ist win32 |
AW: Access Validation bei CreateProcess
Ich bin nicht ganz sicher, meine aber, mich erinnern zu können, dass es aus irgendwelchen Gründen an STARTF_USESTDHANDLES liegt. Hast Du es einmal mit TDOSCommand versucht?
|
AW: Access Validation bei CreateProcess
Zitat:
|
AW: Access Validation bei CreateProcess
Der zweite Parameter ist ein INOUT-Parameter (VAR), welcher unter Umständen dort reinschreiben könnte.
Das könnte man eventuell prüfen, denn ich glaub damit hatte vor einer Weile mal jemand ein Problem. Nimm mal das CONST bei ACommand weg und setze probehalber ein
Delphi-Quellcode:
vor das CreateFile.
ACommand:=ACommand+#0; SetLength(ACommand, MAX_PATH);
|
AW: Access Validation bei CreateProcess
Liste der Anhänge anzeigen (Anzahl: 1)
Sirius' Einverständnis vorausgesetzt hänge ich das Archiv einmal an.
|
AW: Access Validation bei CreateProcess
Thx Damit gehts
|
AW: Access Validation bei CreateProcess
Moin Leute :hi:
Ich weiß, dass der Eintrag alt ist. Ich hatte gerade das gleiche Problem. Das Ergebnis ist der Hammer! Im Beispielcode ist "ACommand" als String deklariert, was eigentlich WideString sein müsst. Trägt man WideString ein, läuft es. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:15 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz