Jump to content

Recommended Posts

Posted

I'm trying to write a script to close all open Explorer windows. (This is useful if you are installing a networking component and have folders on network shares open - avoids the error that the resource can't be reached.) I'm using AutoIt 3.1.0.15.

The problem I'm having is that if I have more than 4 windows, not all the windows close. I did a little debugging, and the issue seems to be that my test for when I reach the end of all the windows isn't correct. In the script below, I test for when $TestWin equals "00000000", but this doesn't seem to work properly - I seem to get this value before all the windows have been tested. The Win32 API documentation I have says

If no window exists with the specified relationship to the specified window, the return value is NULL.

but I'm not sure how to test for that. Any help is appreciated.

Here is the script:

Func CloseExplorerWins()
  Const $BufferLen = 250, $GW_HWNDNEXT = 2, $GW_CHILD = 5
  Local $FirstWin, $RetClass, $WinClass, $WinTitle, $userDll, $DesktopWin, $TestWin
  $userDll = DllOpen ( "User32.dll" )
  $DesktopWin = DllCall( $userDll, "hwnd", "GetDesktopWindow")
  $FirstWin = DllCall( $userDll, "hwnd", "GetWindow", "hwnd", $DesktopWin[0], "long", $GW_CHILD)
  $TestWin = $FirstWin[0] & ""
  While $TestWin <> "00000000"
    $RetClass = DllCall( $userDll, "int", "GetClassName", "hwnd", $FirstWin[0], "str", $WinClass, "int", $BufferLen)
    If $RetClass[2] = "CabinetWClass" Then
      $RetVal = DllCall( $userDll, "short", "PostMessage", "hwnd", $FirstWin[0], "int", 16, "long", 0, "long", 0)
    EndIf
    $FirstWin = DllCall( $userDll, "hwnd", "GetWindow", "hwnd", $FirstWin[0], "long", $GW_HWNDNEXT)
    $TestWin = $FirstWin[0] & ""
  WEnd
  DllClose( $userDll)
EndFunc

Thanks a lot!

BlueBearr

BlueBearrOddly enough, this is what I do for fun.
Posted

Quick and dirty but it will close all open windows of explorer

Tested on winXP Pro

Opt('WinTitleMatchMode',4)

While WinExists('classname=ExploreWClass') Or WinExists('classname=CabinetWClass')
    WinClose('classname=ExploreWClass') 
    WinClose('classname=CabinetWClass')
    Sleep(1)
WEnd
Posted

Dang, that's slick. Thanks, quick and dirty works for me! :(

Now I gotta find another reason to play with DllCall... :(

BlueBearr

BlueBearrOddly enough, this is what I do for fun.
Posted

$TestWin = $FirstWin[0]

While $TestWin <> 0

<{POST_SNAPBACK}>

I tried this and it didn't work - it would never exit the loop. That's why I used the "00000000" value.

BlueBearr

BlueBearrOddly enough, this is what I do for fun.
Posted

I tried this and it didn't work - it would never exit the loop.  That's why I used the "00000000" value.

BlueBearr

<{POST_SNAPBACK}>

Then the function doesn't return NULL
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs

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
  • Recently Browsing   0 members

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