; Opsi Builder to automate the creation of Opsi packages for the Opsi System
;    Copyright (C) 2012  Daniel Schwager
;    Copyright (C) 2014  Mario Fetka
;
;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU Affero General Public License as
;    published by the Free Software Foundation, either version 3 of the
;    License, or (at your option) any later version.
;
;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU Affero General Public License for more details.
;
;    You should have received a copy of the GNU Affero General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.

[ExecWith_BrowserKill]
Option Explicit
KillBrowsers()

Sub KillBrowsers()
'Declare variables
    Dim i
    Dim wmiSvc,WQL,Processes,Process
    Dim arrBrowserProcesses(9)

'Initialize variables
    arrBrowserProcesses(0)="iexplore.exe"
    arrBrowserProcesses(1)="chrome.exe"
    arrBrowserProcesses(2)="firefox.exe"
    arrBrowserProcesses(3)="safari.exe"
    arrBrowserProcesses(4)="opera.exe"
    arrBrowserProcesses(5)="vivaldi.exe"
    arrBrowserProcesses(6)="iron.exe"
    arrBrowserProcesses(7)="MicrosoftEdge.exe"
    arrBrowserProcesses(8)="msedge.exe"

    Set wmiSvc = GetObject("winmgmts:\\.\root\cimv2")
    For i = 0 To UBound(arrBrowserProcesses)
        wql = "SELECT * FROM Win32_Process WHERE Name='" & arrBrowserProcesses(i) & "'"
        Set processes = wmiSvc.ExecQuery(wql)
        Do While processes.Count > 0
            For Each process In processes
                process.Terminate
            Next
            WScript.Sleep 200
            Set processes = wmiSvc.ExecQuery(wql)
        Loop
    Next

End Sub