Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running process

Status
Not open for further replies.

bogboy1978

Technical User
Nov 8, 2002
27
0
0
GB
Does anyone know of a way to kill a specific running process through delphi? I want to make an app that will check for a running process called "ftp server" and kill it if it is running. I have found code to list all the running processes but couldn't work out how to modify it to find a certain process and kill it. Most google searches simply give results on hiding your app from the process list, this is not what I am after.

Thanks in advance.
 
You could try sending a WM_CLOSE message to it, once you have the window handle.
 
There is no window. The process is an invisible app. It doesn't show up in the applications tab when you do ctrl + alt + delete, only in the processes tab, that is why I need direct access to the running process and the ability to shut it down. I know it can be done manually but I want to do it through my app, so I can restart the process when the app is finished.
 
you must use windows API :

find processID
then use OpenProcess with flag PROCESS_ALL_ACCESS and then
use terminateprocess with the obtained handle. don't have sample code for the moment but a quick google search on "terminateprocess delphi" will sure dig up some code.

cheers

--------------------------------------
What You See Is What You Get
 
I forgot about a program I made to 'kill' msn messenger (don't like this program , so if my kids start this one, it will be killed) here ya go :

Code:
program msnstub;

uses
  Windows;

var MSN_handle : integer;
    MSN_Pid    : Cardinal;

begin
  repeat
  // kill code comes here
  MSN_handle:=Findwindow('MSNHiddenWindowClass','');
  if MSN_handle <> 0 then
   begin
    GetWindowThreadProcessId(MSN_handle, MSN_Pid);
    if MSN_pid <> 0 then
     begin
      MSN_handle:=OpenProcess(PROCESS_ALL_ACCESS,Longbool(0),MSN_PID);
      if TerminateProcess(MSN_Handle,0) = False then
       begin
//      Showmessage(IntToStr(Getlasterror));
       end;
     end;
   end;
  //sleep for x msecs
  Sleep(15000);
 until 1 = 0;
end.

--------------------------------------
What You See Is What You Get
 
Whats the "MSNHiddenWindowClass" ??? And what would it be for any other program?

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Hi BobbaFet,

"MSNHiddenWindowClass" is the window class of the hidden MSN messenger window. You can check this with tools like ms Spy++ . bogboy indicates that the process has no window so he'll have to find the ProcessId via the CreateToolhelp32Snapshot function.
in fact it's th32ParentProcessID that can be found in the PROCESSENTRY32 structure. (see windows api sdk help for more details. code sample can be found in this thread : thread102-869282

cheers


--------------------------------------
What You See Is What You Get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top