Wednesday, March 7, 2007

Kill a process in VB .Net

Recently I found my self in need of some code that would kill off all instances of a process. Here is what I came up with:
Dim myProcesses As Process() = Process.GetProcessesByName("QTPro")
Dim myProcess As Process
For Each myProcess In myProcesses
myProcess.Kill()
Next myProcess
One note on this is that the process name is the name without the extension. Eventhough through task manager it list the process name as QTPro.exe I had to use QTPro

No comments: