How can I kill a process by using C#.NET Application?

  • Thread starter Thread starter Thomas Chan
  • Start date Start date
T

Thomas Chan

I have an application that need to launch acrobat reader. But before I
open acrobat reader, I want to check there is any existing acrobat
reader opening and kill them first.

What can I do? Can anyone kindly sugguest some idea?
Thanks
 
I think the process namepsace lets you access only those
processes that you application has started.

If you need to access all the active processes in your
system, then you will have to use WMI through C# code. You
can talk to WMI using System.Management namespace.

WMI gives you api to list processes, abort, kill, etc.

HTH,
Dolly
 
thanks~
i have read through the MSDN...I have tried it...but still don't know how to
do this...
can you give me some reference? (may be a link / sample codes)

many thanks
 
Not only processes your application starts, it can handle all processes in
the system. As long as you can get the process by name or id, you can kill
it by Process.Kill().

-jl
 
¤ I have an application that need to launch acrobat reader. But before I
¤ open acrobat reader, I want to check there is any existing acrobat
¤ reader opening and kill them first.
¤
¤ What can I do? Can anyone kindly sugguest some idea?
¤ Thanks

Try the following:

Public Sub EnumerateProcesses()

Dim WindowsProcess As Process
Dim ProcessToKill As String = "AcroRd32"

For Each WindowsProcess In Process.GetProcesses
Debug.WriteLine(WindowsProcess.ProcessName)
If WindowsProcess.ProcessName = ProcessToKill Then
WindowsProcess.Kill()
End If
Next

End Sub


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top