PDA

View Full Version : Solved: Close all instances of IE



gsouza
09-25-2007, 06:38 PM
Hi everybody, if you could help me, I would like to add a command button on a userform that will close all instances of Internet Explorer with out close the user form. I tryed to search for the answer here and in google but I can not find it. I had it once a long time ago but lost it. If anybody could help, I would greatly appreciate it. Thanks in advance.

rory
09-26-2007, 02:40 AM
You could use something like this:
Sub FindAndTerminate(ByVal strProcName As String)
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcName & "'")
If colProcess.Count > 0 Then
For Each objProcess In colProcess
objProcess.Terminate
Next objProcess
End If
End Sub

just pass "IExplore.exe" as the argument.

gsouza
09-26-2007, 08:17 AM
I can't figure out how to make this work, I have tryed everything. Maybe you can go a little further and show me how to do this so it will work. Thanks for your help

rory
09-26-2007, 09:00 AM
Put that code into a normal module in your project, then in the Click event of your button, you would just use:
findandterminate "IExplore.exe"

gsouza
09-26-2007, 11:23 AM
thanks alot for your help and time.