Jump to content

Recommended Posts

Posted

If i have two or more of the same processes open, is it possible to kill all but one of them using ProcessKill()? ProcessKill will close all of them. If i can get this figured out, i can start programming more IE crap.

Posted

ok, i'm going to a different question instead. Is it possible to close all IE windows except one specified in a variable? i think this was answered before but i searched and couldn't find it

  • Moderators
Posted

ok, i'm going to a different question instead. Is it possible to close all IE windows except one specified in a variable? i think this was answered before but i searched and couldn't find it

HighLander :D

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.

  • Moderators
Posted

wait... it won't work

Did you try to mod it?

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.

  • Moderators
Posted (edited)

_WinCloseSpecial('iexplore.exe', 'Some Name To Keep')

Func _WinCloseSpecial($sExe, $sWinKeep)
    $OptWTMM = Opt('WinTitleMatchMode', 2)
    $sWinKeep = WinGetHandle($sWinKeep)
    Local $aWinList = WinList(), $aProcList = ProcessList()
    Local $aStoreProcess = ''
    For $xCount = 1 To $aProcList[0][0]
        If $aProcList[$xCount][0] = $sExe Then $aStoreProcess &= $aProcList[$xCount][1] & Chr(01)
    Next
    $aStoreProcess = StringSplit(StringTrimRight($aStoreProcess, 1), Chr(01))
    For $iCount = 1 To $aWinList[0][0]
        For $xCount = 1 To UBound($aStoreProcess) - 1
            If WinGetProcess($aWinList[$iCount][0]) = $aStoreProcess[$xCount] Then
                If $aWinList[$iCount][1] <> $sWinKeep Then
                    WinClose($aWinList[$iCount][1])
                EndIf
            EndIf
        Next
    Next
    Opt('WinTitleMatchMode', $OptWTMM)
EndFunc

Edit:

Wish I had read this:

no

Before I posted. Edited by SmOke_N

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.

  • Moderators
Posted

This should work

#include <IE.au3>

; prevent object error from terminating your script
_IEErrorHandlerRegister ()
; create a visible browser window and navigate to a webpage
$oIE = _IECreate ("www.autoitscript.com")
; get the hwnd of the browser window
$hIE = _IEPropertyGet ($oIE, "hwnd")

_KillExistingIE($hIE, 1)

Func _KillExistingIE($h_hwnd, $w_Kill_Close = 0)
    $w_Winlist = WinList()
    For $i = 1 To $w_Winlist[0][0]
        If StringInStr($w_Winlist[$i][0], "Microsoft Internet Explorer") And $w_Winlist[$i][1] <> $h_hwnd Then
            If $w_Kill_Close = 0 Then
                WinKill($w_Winlist[$i][1])
            Else
                WinClose($w_Winlist[$i][1])
            EndIf
        EndIf
    Next
EndFunc   ;==>_KillExistingIE
  • Moderators
Posted

This should work

#include <IE.au3>

; prevent object error from terminating your script
_IEErrorHandlerRegister ()
; create a visible browser window and navigate to a webpage
$oIE = _IECreate ("www.autoitscript.com")
; get the hwnd of the browser window
$hIE = _IEPropertyGet ($oIE, "hwnd")

_KillExistingIE($hIE, 1)

Func _KillExistingIE($h_hwnd, $w_Kill_Close = 0)
    $w_Winlist = WinList()
    For $i = 1 To $w_Winlist[0][0]
        If StringInStr($w_Winlist[$i][0], "Microsoft Internet Explorer") And $w_Winlist[$i][1] <> $h_hwnd Then
            If $w_Kill_Close = 0 Then
                WinKill($w_Winlist[$i][1])
            Else
                WinClose($w_Winlist[$i][1])
            EndIf
        EndIf
    Next
EndFunc   ;==>_KillExistingIE
Would that work if there were more than one .exe running? I had something similar until I thought about that, and the PID being different.

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.

  • Moderators
Posted

It worked for me, I opened three different browsers, then ran the script. All but the one that was created were closed.

Yeah, I'm sorry, I should have said something... I noticed the StringInStr() with Internet Explorer there, that takes care of that.

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.

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
×
×
  • Create New...