Jump to content

Close Apps Script


Recommended Posts

Hey, I have a way of doing this script in a batch file, but I'm wondering if autoit can do it better/faster. I want to close all open IE windows except for the one(s) with certain words in the title bar. With a batch file I can do this:

tasklist /v /NH /FO "CSV" | find /I "iexplore" | find /v /I "TITLE GOES HERE" > tasklist.csv

for /F "eol=; tokens=2,3* delims=," %%i in (tasklist.csv) do taskkill /F /PID %%i

This will create a csv with a list of all open IE apps without the words title goes here in the titlebar, it then closes those.

I've looked around and can't seem to find a way of doing this in AutoIt. Any suggestions?

Thanks!

Eric

Link to comment
Share on other sites

  • Moderators

This should close visible and non-visible as well:

;Make sure you separate the words that are safe by commas
;It will return the number of windows it closed
MsgBox(64, "Info", "Closed: " & _IEKillWins("blah,oops,hey,findme") & " IE Windows.")

Func _IEKillWins($sSafeWords);Seperate words by commas
    Local $aSafe = StringSplit($sSafeWords, ","), $bSafe = False, $nClosed = 0
    Local $aIEWins = WinList("[REGEXPTITLE:.*? - Microsoft Internet Explorer]")
    For $iCC = 1 To UBound($aIEWins) - 1
        For $xCC = 1 To $aSafe[0]
            If StringInStr($aIEWins[$iCC][0], $aSafe[$xCC]) Then
                $bSafe = True
                ExitLoop
            EndIf
        Next
        If $bSafe <> True Then
            WinClose($aIEWins[$iCC][1])
            $bSafe = False
            $nClosed += 1
        EndIf
    Next
    Return $nClosed
EndFunc
Safe words should separated by a comma.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...