Thursday, August 29, 2013

VB Script - Close All Browser

Function Details:
This Vb Script Function is for "Close browsers except QC window" using VB Script.This function will close all the Internet Explorer window and tabs except HP Quality Center. To use this function simply copy paste it in to text file and save the file with .vbs Extension. When you double click on the .vbs file, the script will be executed and you can found the result.

Function CloseIE
    On Error Resume Next

    'Variable Declaration
    dim objShell, objWindow, strTitle

    'Set Variables and Object Values
    set objShell = CreateObject("Shell.Application") 'Create Shell Application Object
    strTitle = "HP Quality Center" 'Set Window Title Search Name
   
    for each objWindow in objShell.Windows 'Get Window Objects
        if InStr(objWindow.FullName,"iexplore")<>0 then 'Check Object Window Full Name with iexplore   
            if(objWindow.document.title<>"") then 'Check Object Window Title not Blank   
                if InStr(objWindow.document.title,strTitle)=0 then 'Check Object Window is not Quality  Center
                    objWindow.Quit 'Close IE
                end if   
            end if   
        end if
    next

    if objShell.Windows.Count>0 then 'Check Object Window Count
        For i=0 to objShell.Windows.Count
            Call CloseIE 'Recursively call Function
        next
    end if

End Function

Note :- To Use this Function write the below statement in top of the .vbs file.
Call CloseIE statement