AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi CreateProcess und mehrere Konsolenbefehle
Thema durchsuchen
Ansicht
Themen-Optionen

CreateProcess und mehrere Konsolenbefehle

Ein Thema von Sunshine21 · begonnen am 30. Jun 2008 · letzter Beitrag vom 2. Jul 2008
Antwort Antwort
Sunshine21

Registriert seit: 26. Jun 2008
27 Beiträge
 
#1

Re: CreateProcess und mehrere Konsolenbefehle

  Alt 1. Jul 2008, 07:46
Hab jetzt mal auf Ratschlag von DeddyH ExecAndWait eingefügt doch beim Aufruf kommt zwar die Konsole aber der Eingabebefehl wird ignoriert.

Aufrufen mit:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ExecandWait('C:\Windows\system32\netsh.exe','interface ip set address name = "LAN1" source = static addr = 192.168.0.1 mask = 255.255.255.0',sw_normal);
end;
Funktion:

Delphi-Quellcode:
{ WindowState is one of the SW_xxx constants.
  Look up ShowWindow in the API help for a list.}

function TForm1.ExecAndWait(const Filename, Params: string;
                     WindowState: word): boolean;
var
  SUInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  CmdLine: string;
begin
  { Enclose filename in quotes to take care of
    long filenames with spaces. }

  CmdLine := '"' + Filename + '" ' + Params;
  FillChar(SUInfo, SizeOf(SUInfo), #0);
  with SUInfo do begin
    cb := SizeOf(SUInfo);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := WindowState;
  end;
  try
    Result := CreateProcess(NIL, PChar(CmdLine), NIL, NIL, FALSE,
                            CREATE_NEW_CONSOLE or
                            NORMAL_PRIORITY_CLASS, NIL,
                            PChar(ExtractFilePath(Filename)),
                            SUInfo, ProcInfo);
  except
    on E: Exception do
      begin
        Result:=false;
      end;
  end;

  { Wait for it to finish. }
  if Result then begin
    Application.Processmessages;
    WaitForSingleObject(ProcInfo.hProcess, INFINITE);
  end;

end;
Edit: Mit Netsh hat es jetzt doch funktioniert. Rufe die Funktion einfach mehrmals auf um mehrere Befehle abzuarbeiten. Der Code oben wurde von mir entsprechend ausgebessert
  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 22:53 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