Autor Beitrag
Codeexplorer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Di 09.01.07 18:27 
Ich möchte ein Dos-Programm für den Benutzer unsichtbar im Hintergrund starten.
Aber jedesmal erscheint das Konsolenfenster für den Bruchteil einer Sekunde.
Folgendermassen sieht mein Code (ist in Delphi geschrieben) aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
function TRexCtrl.RunApp(const sFileName, sArg: string): cardinal;
var
  NewProcess: Process;
begin
  NewProcess := Process.Create;
  with NewProcess do
  begin
    StartInfo.FileName       := sFileName;
    StartInfo.CreateNoWindow := True;
    StartInfo.WindowStyle    := System.Diagnostics.ProcessWindowStyle.Hidden;
    StartInfo.WindowStyle    := System.Diagnostics.ProcessWindowStyle.Minimized;
    try
      Start(sFileName, sArg);
    finally
      if NewProcess<>nil then
      begin
        close;
        NewProcess:=nil;
      end;
    end{end try/except}
  end{end with}
  Result:=0;
end{end function}


Kann mir jemand sagen, wie ich meinem Programm beibringen kann, das Fenster nicht
anzuzeigen ??

Vielen Dank im voraus!
Codeexplorer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Do 11.01.07 19:38 
Na, hat den keiner eine Idee ?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 11.01.07 19:47 
Kann es damit zusammenhängen, dass Du den WindowStyle zweimal setzt? Davon bleibt ja dann nur "Minimized" übrig, weil das "Hidden" überschrieben wird.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Codeexplorer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Fr 12.01.07 13:44 
Sorry, der Quellcode war irreführend. Ich habe da schon mit verschiedenen Möglichkeiten herumexperimentiert. Auch der untenstehende Code zeigt immer das Fenster an, nur mit
dem Unterschied, dass es nicht nur kurz erscheint, sondern dort stehen bleibt, bis sich
der gestartete Prozess terminiert.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
function TRexCtrl.RunApp(const sFileName, sArg: string): cardinal;
var
  NewProcess: Process;
begin
  NewProcess := Process.Create;
  with NewProcess do
  begin
    StartInfo.FileName       := sFileName;
    StartInfo.CreateNoWindow := True;
    StartInfo.WindowStyle    := System.Diagnostics.ProcessWindowStyle.Hidden;
    try
      Start(sFileName, sArg);
    finally
      if NewProcess<>nil then
      begin
        close;
        NewProcess:=nil;
      end;
    end{end try/except}
  end{end with}
  Result:=0;
end{end function}
Codeexplorer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Di 16.01.07 10:28 
Tja, das war wohl ein typischer Fall von Tomaten auf den Augen.
Hier noch mal der Vollständigkeit halber der korrekte Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
function TRexCtrl.RunApp(const sFileName, sArg: string): cardinal;
var
  NewProcess: Process;
begin
  NewProcess := Process.Create;
  with NewProcess do
  begin
    StartInfo.FileName       := sFileName;
    StartInfo.Arguments      := sArg;
    StartInfo.CreateNoWindow := True;
    StartInfo.WindowStyle    := System.Diagnostics.ProcessWindowStyle.Hidden;
    try
      // 30 sec Timeout
      Start(StartInfo).WaitForExit(30000);
    finally
      if NewProcess<>nil then
      begin
        close;
        NewProcess:=nil;
      end;
    end{end try/except}
  end{end with}
  Result:=0;
end{end function}