AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Dos-Programm öffnen

Ein Thema von Alexander · begonnen am 16. Jan 2003 · letzter Beitrag vom 18. Jan 2003
Antwort Antwort
Gast
(Gast)

n/a Beiträge
 
#1
  Alt 16. Jan 2003, 18:16
Willst du eine Nachricht empfange vom Dos, oder nur eine bestätigung ob das programm beendet wurde, ich kann dir geben, das du das im tmemo stehen hast, was im dos steht.

Das ist eigendlich ganz einfach:

Delphi-Quellcode:
procedure CaptureDos(command:String;Stringsp:TStrings);
const
  CaptureBufferSize = 2500;
var
  SecAttrib : TSecurityAttributes;
  ReadPipe,writePipe : THandle;
  Startup : TStartUpInfo;
  ProcessInfo : TProcessInformation;
  CaptureBuffer : Pchar;
  BytesRead : DWord;
  WaitHandle : DWord;
begin
  Stringsp.clear;
 Stringsp.add('Starte "'+command+'"');
  With SecAttrib do
  begin
    nlength := SizeOf(TSecurityAttributes);
    binherithandle := true;
    lpsecuritydescriptor := nil;
  end;
  if Createpipe (ReadPipe, writePipe, @SecAttrib, 0) then
  begin
    CaptureBuffer := AllocMem(CaptureBufferSize + 1);
    FillChar(Startup,Sizeof(Startup),#0);
    Startup.cb := SizeOf(Startup);
    Startup.hStdOutput := writePipe;
    Startup.hStdInput := ReadPipe;
    Startup.dwFlags := STARTF_USESTDHANDLES +
                           STARTF_USESHOWWINDOW;
    Startup.wShowWindow := SW_SHOW;

    if CreateProcess(nil,
      PChar(command),
      @SecAttrib,
      @SecAttrib,
      true,
      NORMAL_PRIORITY_CLASS,
      nil,
      nil,
      Startup,
      ProcessInfo) then
    begin
      repeat
        WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,100);
        Application.ProcessMessages;
      until (WaitHandle <> WAIT_TIMEOUT) or application.terminated;
      if not application.terminated then
      Repeat
        BytesRead := 0;
        ReadFile(ReadPipe,CaptureBuffer[0],CaptureBufferSize,BytesRead,nil);
        CaptureBuffer[BytesRead]:= #0;
        OemToAnsi(CaptureBuffer,CaptureBuffer);
        Stringsp.Text := Stringsp.Text+String(CaptureBuffer);
      until (BytesRead < CaptureBufferSize);
      end else Stringsp.add('Fehler!');
    FreeMem(CaptureBuffer);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ReadPipe);
    CloseHandle(writePipe);
  end else Stringsp.add('Konnte Dos Kommando nicht starten, Fehler: #'+
  inttostr(getlasterror));
end;
Um die prozedur auszuführen, benutzt du z.B.
procedure CaptureDos('dir c:',Memo1->Lines);

dann bekommste dein dos komando.

[keine garantie, habe ich aus c++ übersetzt...]

Falls ein fehler auftreten sollte, bitte melden!
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:06 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-2025 by Thomas Breitkreuz