Reputation: 13
I try to create code which closes/kills all the browsers. How to do this?
I create code like this:
Set obj = CreateObject("InternetExplorer.Application")
obj.Quit
Set obj = CreateObject("Chorme.Application")
obj.Quit
Set obj = CreateObject("Firefox.Application")
obj.Quit
but it doesn't work.
Any idea to write script for close the all browser at once? Like we see in CCleaner.
Upvotes: 1
Views: 15984
Reputation: 200503
You can do this without shelling out:
Set wmi = GetObject("winmgmts://./root/cimv2")
browser = "iexplore.exe"
qry = "SELECT * FROM Win32_Process WHERE Name='" & browser & "'"
For Each p In wmi.ExecQuery(qry)
p.Terminate
Next
Upvotes: 2
Reputation: 1392
CreateObject can only be used to operate the COM or ActiveX object, but unluckily Chrome or Firefox is not ActiveX . To work as expected, you can fire with tasklist and taskkill.
Tasklist can list the process name with pid, and taskkill can terminate the process with specified id.
tasklist /fi "imagename eq iexplore.exe"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
iexplore.exe 2448 Console 1 63,124 K
iexplore.exe 2752 Console 1 304,312 K
iexplore.exe 4660 Console 1 230,492 K
iexplore.exe 1908 Console 1 211,332 K
iexplore.exe 4536 Console 1 148,400 K
iexplore.exe 3760 Console 1 136,800 K
iexplore.exe 3652 Console 1 206,788 K
iexplore.exe 2248 Console 1 198,296 K
taskkill /fi "imagename eq iexplore.exe"
code in vbs
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("taskkill /fi ""imagename eq iexplore.exe""")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
Upvotes: 1