Autor Beitrag
ppl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53



BeitragVerfasst: Sa 29.11.08 18:05 
Guten Tag,

ich frage mich ob es möglich ist Firefox "Normal" über delpgi zu beenden, ohne den prozess firefox.exe zu killen,

den ich bastle mir gerade so nen link klicker, und wenn ich firefox über den prozess kille also "firefox.exe"
kann der link klicker beim nächsten start den link nicht öffnen, dennfirefox fragt dann ob er wiederhergestellt werden soll
oder normal starten soll, da das programm ja vorher "abgestürzt" ist

gibts da was?
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Sa 29.11.08 18:18 
Probier doch mal mit Termintate und SendMessage :nixweiss:

_________________
Die Lösung ist nicht siebzehn.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 29.11.08 18:47 
Wenn du selbst Firefox gestartet hast, dann hast du ja dessen Handle schon. (Wenn du es mit CreateProcess gemacht hast.)

Und dann geht das mit SendMessage und WM_CLOSE am schnellsten.
ppl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53



BeitragVerfasst: Sa 29.11.08 18:57 
zum starten nehme ich "ShellExecute (Handle, 'open', PWideChar(edit1.text), nil, nil, SW_SHOW);"

und "SendMessage(handle, WM_CLOSE, 0, 0);" wollte ich zum beenden nehmen,

klappt allerdings nicht, ist es falsch?

sry bin anfänger in delphi
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 29.11.08 18:58 
Naja, dann musst du dir ja erstmal das handle holen, wenn du es so schreibst wäre handle ja das deines eigenen Programms.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 29.11.08 19:00 
Nimm ShellExecuteEx, dann hast Du das Prozesshandle im Feld hProcess der Struktur SHELLEXECUTEINFO.
ppl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53



BeitragVerfasst: Sa 29.11.08 19:01 
sry weiß aber net wie ich mir das handle hole bzw.

obs hier drin steht
"ShellExecute (Handle, 'open', PWideChar(edit1.text), nil, nil, SW_SHOW);"


kannst du mir das villt bisschien genauer erklären?

PS: ja das war das handle meines eigenen programms ^^ daher schließt es sich jetzt von selbst -.-
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 29.11.08 19:09 
Hier siehst du die Verwendung von CreateProcess:
www.delphicorner.f9....k/articles/wapi4.htm
Nach dem Aufruf wird das Handle ProcInfo.hProcess zum Warten benutzt, an der Stelle kannst du das Handle speichern um es dann zum Schließen zu verwenden.

Und hier eins für das auch genannte ShellExecuteEx:
www.delphipraxis.net/topic49304.html

Das hättest du über die genannten Stichworte aber auch selbst finden können. Wie die Funktionen heißen wusstest du ja dann, und dann kannst du auch mal Google selbst benutzen...
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 29.11.08 19:20 
// Firefox starten und später beenden

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  ProcID: Cardinal;
begin
  RunProcess(Edit1.Text, SW_SHOW, True, @ProcID); // Firefox starten
  Sleep(6000); // ein wenig warten ...
  CloseFireFox(ProcID); // Firefox beenden
end;


Diese 2 Funktionen werden benötigt

ausblenden volle Höhe 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:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
procedure CloseFireFox(ProcID: Cardinal);

function EnumWin(hWnd: THandle; ProcID: PCardinal): Bool; stdcall;
var
  WinProcId: Cardinal;
  ClassName: array[0..25of char;
begin
    Result := True;
    GetWindowThreadProcessID(hWnd, WinProcId);
    if ProcID^ = WinProcId then
    begin
       GetClassName(hWnd, ClassName, 25);
      if AnsiPos('MozillaUIWindowClass', ClassName) <> 0  then
      begin
        SendMessage(hWnd, WM_CLOSE, 00);
        Result := False;
      end;
    end;
end;

begin
  EnumWindows(@EnumWin, integer(@ProcID));
end;

function RunProcess(FileName: string; ShowCmd: DWORD; WaitInputIdle: Boolean; ProcID: PCardinal): Longword;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb := SizeOf(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
  StartupInfo.wShowWindow := ShowCmd;
  if not CreateProcess(nil,
    @Filename[1],
    nil,
    nil,
    False,
    CREATE_NEW_CONSOLE or
    NORMAL_PRIORITY_CLASS,
    nil,
    nil,
    StartupInfo,
    ProcessInfo)
    then
    Result := WAIT_FAILED
  else
  begin
    if WaitInputIdle = FALSE then
    begin
      if ProcID <> nil then ProcID^ := ProcessInfo.dwProcessId;
    end else
    begin
      if ProcID <> nil then
        ProcID^ := ProcessInfo.dwProcessId;
      WaitForInputIdle(ProcessInfo.hProcess, INFINITE);
      GetExitCodeProcess(ProcessInfo.hProcess, Result);
    end;
  end;
  if ProcessInfo.hProcess <> 0 then
    CloseHandle(ProcessInfo.hProcess);
  if ProcessInfo.hThread <> 0 then
    CloseHandle(ProcessInfo.hThread);
end;