How to terminate a Process by Name ?? 
Author Message
 How to terminate a Process by Name ??

Hello !

I want to terminate a Process (on win2000) like the Taskmanager but now
in C++ with VisulaC. My Question: In the Taskmanager, each Process has
a name. How Can I Terminate a Process by this name ? How Do I get the
ProcessID, if I only know the Application Name ? The Process has no
window so I can not use FindWindow() and the WM_CLOSE Msg (ist his
correct ?).

Please give me an answear also to my Email, because I'm behind a
firewall and have only at home access to the newsgroups...
thanks !
You can write in German or english...

sincere M.Egloff

--
////////////////////////////////////////////////////////////////////////
// Egloff Mark             Zellweger Uster
// Dipl. Ingenieur         Wilstrasse 11, CH-8610 Uster

//www.uster.com           fax    ++41 1 943 38 22
////////////////////////////////////////////////////////////////////////
The flesh is a trap but the magic gives us the freedom.....

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 23 Dec 2002 03:00:00 GMT  
 How to terminate a Process by Name ??
Hello !

I want to terminate a Process (on win2000) like the Taskmanager but now
in C++ with VisulaC. My Question: In the Taskmanager, each Process has
a name. How Can I Terminate a Process by this name ? How Do I get the
ProcessID, if I only know the Application Name ? The Process has no
window so I can not use FindWindow() and the WM_CLOSE Msg (ist his
correct ?).

Please give me an answear also to my Email, because I'm behind a
firewall and have only at home access to the

You can write in German or english...

sincere M.Egloff

--
////////////////////////////////////////////////////////////////////////
// Egloff Mark             Zellweger Uster
// Dipl. Ingenieur         Wilstrasse 11, CH-8610 Uster

//www.uster.com           fax    ++41 1 943 38 22
////////////////////////////////////////////////////////////////////////
The flesh is a trap but the magic gives us the freedom.....

Sent via Deja.com http://www.deja.com/
Before you buy.



Mon, 23 Dec 2002 03:00:00 GMT  
 How to terminate a Process by Name ??
Egloff Mark a crit :

Quote:
> My Question: In the Taskmanager, each Process has
> a name. How Can I Terminate a Process by this name ? How Do I get the
> ProcessID, if I only know the Application Name ? The Process has no
> window so I can not use FindWindow() and the WM_CLOSE Msg (ist his
> correct ?).

Enumerate the processes until you find yours, then OpenProcess(),
TerminateProcess(), CloseHandle()
KB : http://support.microsoft.com/support/kb/articles/q175/0/30.asp


Mon, 23 Dec 2002 03:00:00 GMT  
 How to terminate a Process by Name ??

Quote:
> I want to terminate a Process (on win2000) like the Taskmanager but now
> in C++ with VisulaC. My Question: In the Taskmanager, each Process has
> a name. How Can I Terminate a Process by this name ? How Do I get the
> ProcessID, if I only know the Application Name ? The Process has no
> window so I can not use FindWindow() and the WM_CLOSE Msg (ist his
> correct ?).

Christian's method will work but it is a drastic measure, to be taken only
when you must. After you get the process ID, you might try enumerate all top
level windows and for each call GetWindowThreadProcessId(). For those (there
may be more than one) that have the process id of the target task you may
want to try sending a WM_SYSCOMMAND/SC_CLOSE message. That's far more polite
although the request may be declined by the app or the user.

Regards,
Will



Mon, 23 Dec 2002 03:00:00 GMT  
 How to terminate a Process by Name ??
Thank you at all !!
It works fine....

sincere M.Egloff

Here is my Code as Example for others:
( I know terminateProcess is not very nice...but for the first use and
tests...why not....; ) )

-----------------------------------------------------------
PROCESSENTRY32 ProcEntry;
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
// create handle to access to the process list
if (Process32First(hSnapShot,&ProcEntry))
{ // get first process in list
  if ( Pocess32First(hSnapShot,&ProcEntry))
  {  // get next process in list until all are checked in list
    while(Process32Next(hSnapShot,&ProcEntry))
    {  // get execfile of current processentry form list
       CString szExeFile = ProcEntry.szExeFile;
       // make upper Letters
       szExeFile.MakeUpper();
       // check if this process is the rigth
       if(szExeFile=="REPAPP.EXE")
       {  // get access to this process to terminate it
        HANDLE hProc = OpenProcess
(PROCESS_TERMINATE,FALSE,ProcEntry.th32ProcessID);
        if (hProc) TerminateProcess(hProc,0);
        CloseHandle(hProc);
        }
   }

Quote:
}

CloseHandle(hSnapShot);

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 24 Dec 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to terminate a Process by Name ??

2. Getting process name in the process

3. Solution for retrieving the process name based on its process ID

4. Getting function name/process from within running process.

5. Find out the name of a process (process.exe) from a window handle (CWnd)

6. Terminating a child process

7. Process suddenly terminates without notification

8. terminate process

9. Debugged Process will not Terminate under Win2K

10. Process suddenly terminates without notification

11. Terminate Process and SecurityIno ?

12. Find and terminate a process under WIN98

 

 
Powered by phpBB® Forum Software