Autor Beitrag
MarkusBauer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70

Win XP Pro
Delphi 7 PE+Indy
BeitragVerfasst: Fr 01.12.06 19:22 
Hallo, ich brauche für ein Programm eine Prozedur, die alle geöffneten Anwendungen ohne Nachfrage schließt. Hat jemand eine Idee, wie man so etwas verfassen könnte?
Markus
andras
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 460

Win XP, Win Vista Home Premium, Ubuntu Dapper Drake
Delphi 2005 Pers
BeitragVerfasst: Sa 02.12.06 20:16 
wie du alle geöffneten programm erkennst, weiß ich nicht, aber ich hab da einen codeschnipsel wie du einen prozess abschießt:
ausblenden Delphi-Quelltext
1:
uses shellapi;  //bin mir nicht mehr ganz sicher, ob man das braucht....					

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
function TForm1.KillTask(const AExeName: string): boolean;
var
  p: TProcessEntry32;
  h: THandle;
begin
  Result := false;
  p.dwSize := SizeOf(p);
  h := CreateToolHelp32Snapshot(TH32CS_SnapProcess, 0);
  try
    if Process32First(h, p) then
      repeat
        if AnsiLowerCase(p.szExeFile) = AnsiLowerCase(AExeName) then
          Result := TerminateProcess(OpenProcess(Process_Terminate,
                                                 false,
                                                 p.th32ProcessID),
                                     0);
      until (not Process32Next(h, p)) or Result;
  finally
    CloseHandle(h);
  end;
end;

es reicht der name der exe-datei (z.b.: word.exe). der pfad ist egal.
erklären kann ich dir den code leider nicht. weiß selber nicht mehr von wo der ist.
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Sa 02.12.06 20:33 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.KillAllTasks;
var
  p: TProcessEntry32;
  h: THandle;
begin
  p.dwSize := SizeOf(p);
  h := CreateToolHelp32Snapshot(TH32CS_SnapProcess, 0);
  try
    if Process32First(h, p) then
      repeat
        TerminateProcess(OpenProcess(Process_Terminate, false, p.th32ProcessID), 0);
      until not Process32Next(h, p);
  finally
    CloseHandle(h);
  end;
end;

So kannst du alle Prozesse beenden, aber ich glaube du willst nur die Prozesse beenden, die auch ein Fenster haben, oder?