Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Is there a way in VB to kill a running process on a computer from a VB application, that infact has nothing to do with the application. For example if you have the internet open the process is "IEXPLORE.EXE" and I want to kill that process with a click of a button on a vb windows form. Is there a way to accomplish this and if so how? Any help given is greatly appreciated.
Posted

Use the Process Class.

 

c# code

static void KillProcesses()
{
System.Diagnostics.Process[] proccesses = System.Diagnostics.Process.GetProcessesByName("IEXPLORE");
try
{
	foreach(System.Diagnostics.Process process in proccesses)
		process.Kill();
}
finally
{
	foreach(System.Diagnostics.Process process in proccesses)
	{
		try
		{
			process.Dispose();
		}
		catch
		{
		}
	}
}
}

 

decompiled as vb

private static void KillProcesses()
{
     Process[] processArray1 = Process.GetProcessesByName("IEXPLORE");
     try
     {
           Process[] processArray2 = processArray1;
           for (int num1 = 0; num1 < processArray2.Length; num1++)
           {
                 Process process1 = processArray2[num1];
                 process1.Kill();
           }
     }
     finally
     {
           Process[] processArray3 = processArray1;
           for (int num2 = 0; num2 < processArray3.Length; num2++)
           {
                 Process process2 = processArray3[num2];
                 try
                 {
                       process2.Dispose();
                 }
                 catch
                 {
                 }
           }
     }
}


  • Leaders
Posted

Thats... decompiled to C#. Try this:

 

Sub KillProcesses()
   Dim Proccesses As System.Diagnostics.Process() =  _ 
       System.Diagnostics.Process.GetProcessesByName("IEXPLORE")
   Try
       For Each Process As System.Diagnostics.Process In Proccesses
           Process.Kill()
       Next
   Catch
   Finally
       For Each Process As System.Diagnostics.Process In Proccesses
           Try
               Process.Dispose()
           Catch
           End Try
       Next
   End Try
End Sub

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...