Autor Beitrag
Dauersuchti
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Do 05.05.05 18:39 
Ich hab jetzt mal ausführlich hier im Forum rumgesucht und viele schöne Threaths zu dem Thema gefunden, doch hat mir keine wirklich weiter geholfen.

Ich will einfach nur ein Programm per buttonklick beenden.

Da stand zwar auch irgend so was in nem Threath drin aber da war n riesenlanger Quellcode drin mit sonst was für Befehlen die ich gar net will, ich möchte einfach nur ein Programm beenden können. Am liebsten mit na Tastenkombi wie Str+Alt+Q oder so aber das bekomm ich schon hin wenn mir wer zeigt wie des per Buttonklick klappt
Felux
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 57

WinXP Home + Sp1
D6 Pers(eng), D2005 Prof(de), Webocton Scriptly, C# (VS 2005 Express), Eclipse
BeitragVerfasst: Do 05.05.05 18:44 
Doppelklick auf Button und dann in die Procedure folgenden Code schreiben:

ausblenden Delphi-Quelltext
1:
application.terminate					
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: Do 05.05.05 18:46 
Er will doch ein anders Programm beenden nicht das eigene.

_________________
Gruß Harry
Et spes me per dies sine te ducat et amor me ferat, si dolor spem tollit.
Dauersuchti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Do 05.05.05 18:46 
und wie gebe ich da die Datei/das Programm ein welches beendet werden soll ?

Axo das ist fürs eigene Programm ? Das möchte ich eigentlich nicht ich möchte ein anderes Programm beenden.
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: Do 05.05.05 18:57 
Das da soviel Code steht hat seinen Grund!
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:
uses
  Tlhelp32

function KillTask(ExeFileName: string): Integer;
const
  PROCESS_TERMINATE = $0001;
var
  ContinueLoop: BOOL;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
begin
  Result := 0;
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
  ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);

  while Integer(ContinueLoop) <> 0 do
  begin
    if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
      UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
      UpperCase(ExeFileName))) then
      Result := Integer(TerminateProcess(
                        OpenProcess(PROCESS_TERMINATE,
                                    BOOL(0),
                                    FProcessEntry32.th32ProcessID),
                                    0));
     ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
  end;
  CloseHandle(FSnapshotHandle);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
   KillTask('notepad.exe');
end;


Du kannst Prozesse auch noch über die PID beenden, was eigendlich die bessere Wahl ist.

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:
procedure KillProcess(dwProcID: DWORD);
var
  hProcess : Cardinal;
  dw       : DWORD;
begin
  { open the process and store the process-handle }
  hProcess := OpenProcess(SYNCHRONIZE or PROCESS_TERMINATE, False, dwProcID);
  { kill it }
  TerminateProcess(hProcess, 0);
  { TerminateProcess returns immediately, so wie have to verify the result via
    WaitfForSingleObject }

  dw := WaitForSingleObject(hProcess, 5000);
  case dw of
    { everythings's all right, we killed the process }
    WAIT_OBJECT_0: Messagebox(Application.Handle, 'Prozess wurde beendet.', 'Prozess beenden',
      MB_ICONINFORMATION);
    { process could not be terminated after 5 seconds }
    WAIT_TIMEOUT:
    begin
      Messagebox(Application.Handle, 'Es konnte innerhalb von fünf Sekundnen ein Prozeß nicht beendet werden!',
        'Prozess beenden', MB_ICONSTOP);
      CloseHandle(hProcess);
      exit;
    end;
    { error in calling WaitForSingleObject }
    WAIT_FAILED:
    begin
      RaiseLastOSError; 
      CloseHandle(hProcess);
      exit;
    end;
  end; 
  CloseHandle(hProcess);
  { and refresh listbox contend }
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  KillProcess(1612); // 1612 ist die (aktuelle!!!!!!) PID vom Notepad
end;

Hier lohn sich ein Besuch bei Luckie: www.luckie-online.de...ocList_KillProc.html

_________________
Gruß Harry
Et spes me per dies sine te ducat et amor me ferat, si dolor spem tollit.
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Do 05.05.05 19:17 
Jetzt habe ich so lange gebraucht, um mir den Code anzuschauen, es wäre einfach schade drum, auch wenn die Antwort schon gepostet wurde.

Klick
Ist zwar ein wenig unübersichtlich und vom Stil nicht das eleganteste, aber an sich eine Implementierung, die auf den ersten Blick funktionieren sollte. Allerdings verlässt sich die Funktion darauf, daß das Image als erstes von EnumProcessModules() zurückgegeben wird, normalerweise sollte man sich nie auf solche Dinge verlassen, selbst wenn man es kann ;-) Man sollte also bei Gelegenheit den FAQ-Beitrag mal mit GetProcessImageFile() implementieren.

Harry M. hat folgendes geschrieben:
Du kannst Prozesse auch noch über die PID beenden, was eigendlich die bessere Wahl ist.
"Auch noch"? Geht's denn auch anders (sauber)? Du besorgst dir die PID über den Snapshot, anders kannst du OpenProcess() nicht dazu bringen, dir einen Prozess zurückzuliefern ;-)

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Dauersuchti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Do 05.05.05 19:22 
Ok dann werde ich mich wohl durch den Quellcode durcharbeiten müssen, bleibt mir wohl nix anderes übrig, nur noch eine frage (ich weiß für jede frage nen neune thread bla bla ist aber nur ne kleine Frage), wie mach ich das mit den Tastenkombinationen ?
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Do 05.05.05 19:31 
user profile iconDauersuchti hat folgendes geschrieben:
wie mach ich das mit den Tastenkombinationen ?
Global? Suche im MSDN REGISTERHOTKEY() oder *klick*.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: Do 05.05.05 19:31 
Das sollte sich über Hotkey realieren lassen. Such mal im Forum.

_________________
Gruß Harry
Et spes me per dies sine te ducat et amor me ferat, si dolor spem tollit.
Dauersuchti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Fr 06.05.05 09:50 
Cool danke für euer Hilfe =), auch wenn ich das mit dem Programmbeenden wahrscheinlich nicht hin bekomme, weil das doch noch etwas zu hoch für mich ist.

Aber wer weiß eines Tages, wer ich wohl auf eurer Höhe sein ... *gg* wie das klingt