Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Killing internet browser processes ? 2

Status
Not open for further replies.

crackoo

Programmer
Feb 17, 2011
132
TN
Hi !
I need to create a Sub that is able to kill running internet browsers. After killing a browser process, it needs to check again that there isn't another instance running. For example,the script would check to see if Internet Explorer was running. In testing the script could see that "iexplore.exe" or "FireFox" or "Chrome.exe" was running and would kill the process. I would see all browser windows closed through the single process even though there were many instances listed in Task Manager.
I have this code from the Net but i don't know how to kill them ?

Code:
Set wmiSvc = GetObject("winmgmts:\\.\root\cimv2")
wql = "SELECT * FROM Win32_Process WHERE Name='iexplore.exe' OR Name='firefox.exe'"
Set procs = wmiSvc.ExecQuery(wql)
Do While procs.Count > 0
 ' do stuff
 'procs.Terminate()??
 'TerminateProcess(procs) ??
 'Set procs = wmiSvc.ExecQuery(wql)
Loop

Thank you in advance !
 
Set procs = wmiSvc.ExecQuery(wql)
For Each proc In procs
proc.Terminate()
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Code:
sub killProcess(strProcessName)
	set colProcesses = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_Process Where Name='" & strProcessName & "'")
	if colProcesses.count <> 0 then
		for each objProcess in colProcesses
			objProcess.Terminate()
		next
	end if
end sub 

killProcess "iexplorer.exe"
killProcess "firefox.exe"

What you have so far is pretty close to what you need. Compare it to the code I've posted to fill in the blanks.

The query returns all processes that are named <strProcessName>. It then loops through and terminates the processes

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
It works very nice ! Thank you for your helpful answer !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top