Home > Uncategorized > start/kill processes with VB.net

start/kill processes with VB.net

a friend was just asking me over MSN messenger how to start and kill processes using VB.net, so here is some info on it:
 
* to start a process you can just do
 Process.Start("test.exe")
or
 Dim proc As New ProcessStartInfo()
 proc.Filename = "test.exe"
 Process.Start(proc)
 
see 
 
* to kill a process you can do something like (haven’t tried it though):
 
Dim plist As Process() = Process.GetProcesses()
For Each p As Process in plist
 Try
  If p.MainModule.ModuleName.ToUpper() ="TEST.EXE" Then p.Kill()
 Catch
  ‘seems listing modules for some processes fails, so better ignore any exceptions here
 End Try
Next p
 
see

Categories: Uncategorized Tags:
  1. ppavlino
    2008/07/10 at 09:06

    Use the management console and find the Index service then stop and disable it? You can also turn of indexing in the control panel. Talk about doing things the hard way!

  2. George
    2008/08/01 at 13:35

    unfortunately in my case that silly process wasn\’t responding to this setting (probably was infected with something)

  3. George
    2008/08/01 at 13:38

    Speaking of malicious processes, it\’s better to freeze them than kill them sometimes. SysInternals (now MS) free ProcessExplorer can do that, by allowing you to pause a process (maybe they break into the process with the debugger, not sure how they implement the pausing/freezing of the process) while you try to remove it. Then you search for files handles it keeps open and remove them so that you can then delete that process DLLs and other files and any registry entries it makes to make it not run again (see http://www.sysinternals.com)

  4. George
    2008/09/11 at 00:51

    Just changed "GetProcesses()" to "Process.GetProcesses()"

  5. George
    2008/09/11 at 00:56

    removed import of System.Diagnostics namespace, doesn\’t seem to be needed

  1. No trackbacks yet.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.