PDA

View Full Version : vba to terminate Chrome Browser



Emoncada
11-17-2014, 04:45 PM
I need to be able to click a button to end Chrome.exe Process. What is the best way to accomplish this?
I don't want it to prompt anything just close it.

Aflatoon
11-19-2014, 08:38 AM
Perhaps:

Sub FindAndTerminate(ByVal strProcName As String) Dim objWMIService, objProcess, colProcess
Dim strComputer
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


Called with:

FindAndTerminate "chrome.exe"