How to control Windows processes

UncleRonin

Well-known member
Joined
Feb 28, 2006
Messages
230
Location
South Africa
Programming Experience
5-10
Lately spyware has been going nuts so I was thinking of making an application which displays a list of all current processes, their executable files location and allows you to stop/start a process. Oh, and also shows you the process attributes like local, system, etc. Is it possible to do something like this in .NET? I found the process class but I realy don't know what does what. Has anyone worked with processes before?
 
Hi,

Use the following code to get the details of the process and display on the grid. To stop a process you can use objProcess.kill using the process id. To start a new process you can use


VB.NET:
System.Diagnostics.Process.Start("FileName.exe")


Code to list the process running in the system..


VB.NET:
Dim objDt As New DataTable
objDt.Columns.Add("PID")
objDt.Columns.Add("Process Name")
objDt.Columns.Add("Process Path")
For Each objProcess As Process In Process.GetProcesses()
     If objProcess.ProcessName <> "System" And objProcess.ProcessName <> "Idle" Then
          Dim objDR As DataRow
          objDR = objDt.NewRow
          objDR(0) = objProcess.Id
          objDR(1) = objProcess.ProcessName
          objDR(2) = objProcess.MainModule.FileName
          objDt.Rows.Add(objDR)
     End If
Next
DataGrid1.DataSource = objDt


Regards,
Karthik Simha
 
Ah okay. Thanks for the info! I'm guessing you had to work with this in the past? How do you determine whether or not a process is killable? So that if you went to Task Manager and tried to end the process and it can't be stopped there is some way of finding this out. Probably just catch an exception i'm guessing?
 
Just incase you were wondering, or seeking some inspiration, this particular wheel has already been invented.

google for sysinternals procexp
 
^^ Shot. I've been looking for something like this as well but I want to do it myself as well so that I can get more experience with this kind of thing. The more I learn the better!

Back to my previous post though: Is there some way of determining whether a process CAN be stopped or would this just be included in error handling? It would be pretty terrible if you had to try and kill a process just to see if it is killable. *scratch* Kinda funky isnt it?
 
i think youd think about it the other way round.. you only want to kill certain processes, so you find out when you kill them if they are killable or not..
 
Back
Top