Jump to content

Recommended Posts

Posted
Posted

Since you are not the only one who has asked questions about the desktop I'll implement the code. But it'll not be soon. I'll recommend you to ask the question in the General Help and Support forum. The desktop can also be automated with standard automation code.

  • 3 weeks later...
Posted

Hi Larsj,

is there a way to get the location of selected file into a variable??
i tried to run the example script given in step1 and i jus wanted to know what are the variables that hold the location of focused file??
 

Posted

Example 4) and 5) in post 7 uses GetFiles( True, True ) and GetFolders( True, True ) to get selected files or folders with full path in Windows Explorer. Use GetItems( True, True ) to get all selected items with full path no matter if it's files or folders.

This code works in Windows Explorer. It does not work on the Desktop, and it does not work in an Open or Save dialog.

  • 5 months later...
Posted

@LarsJ I Was messing with grabbing the hWnd and IDispatch object of the desktop window using FindWindowSW() and Just couldn't seem to get it to work 

then looking at the source I notices the declaration was just hResult()

So I Expanded it to this:

"FindWindowSW hresult(variant*;variant*;int;long*;int;ptr*);" & _     ; Finds a window in the Shell windows collection and returns the window's handle and IDispatch interface.

So I assume the definition needs expanded for all items not implemented yet or is there a way to do late binding that I'm missing??

Posted (edited)

You can Use the desktop for most of the examples With the addition of a couple of functions:

  Reveal hidden contents
; Get an IShellBrowser interface
    FindDesktopShellBrowser() ;GetIShellBrowser( $hExplorer )
    
    ;And... If needed...
    
    ;Toggle Desktop
    ToggleDesktop(ObjCreate("shell.application"))

Created Example Setting Destop View / Icon Size

#include "Includes\AutomatingWindowsExplorer.au3"

Opt("MustDeclareVars", 1)

Example()

Func Example()
    Local $objShell = ObjCreate("shell.application")
    Local Const $asFVM_VIEWS =["", "Icon", "Small Icon", "List", "Details", "Thumbnail", "Tile", "Thumbstrip", "Content", ""]
    ; Get an IShellBrowser interface
    FindDesktopShellBrowser()

    If Not IsObj($oIShellBrowser) Then
        MsgBox(0, "Automating Windows Explorer", "Could not get Desktop IShellBrowser interface. Terminating.")
        Return
    EndIf

    ; Get other interfaces
    GetShellInterfaces()

    ; Get current icon view
    Local $view = GetIconView()


    Local $iView, $iSize, $iSzRand, $sViewSz
    If IsArray($view) Then ; OS > XP
        ToggleDesktop($objShell) ;Show The Desktop
        $iView = $view[0] ; Icon view
        $iSize = $view[1] ; Icon size
        $sViewSz = "Icon View = " & $asFVM_VIEWS[$iView] & ", Size = " & $iSize

        ConsoleWrite ("Initial: " & $sViewSz & @CRLF)

        For $i = $FVM_FIRST To $FVM_LAST
            $iSzRand = Random(16, 64, 1)
            $sViewSz = "Icon View = " & $asFVM_VIEWS[$i] & ", Size = " & $iSzRand
            ConsoleWrite ($sViewSz & @CRLF)
            SetIconView($i, $iSzRand) ; Set  view
            MsgBox(0, "Desktop View", "Current View: " & $sViewSz & @CRLF & "Next View: " & $asFVM_VIEWS[$i + 1])
        Next

        SetIconView($iView, $iSize) ; Restore old view

    Else ; OS = XP
        $iView = $view
        If $iView <> $FVM_DETAILS Then ; Not details view
            SetIconView($FVM_DETAILS) ; Set details view
        ElseIf $iView <> $FVM_ICON Then ; Not icon view
            SetIconView($FVM_ICON) ; Set icon view
        EndIf
        Sleep(3000) ; Wait 3 seconds
        SetIconView($iView) ; Restore old view
    EndIf
EndFunc   ;==>Example

Func FindDesktopShellBrowser()
    Local $_dtag_IShellWindows = $dtag_IShellWindows
    ;Populate Method
    $_dtag_IShellWindows = StringReplace($_dtag_IShellWindows, "FindWindowSW hresult();", _
            "FindWindowSW hresult(variant*;variant*;int;long*;int;ptr*);")

    Local Const $CSIDL_DESKTOP = 0
    Local Enum $SWC_EXPLORER = 0x00, $SWC_BROWSER = 0x01, $SWC_3RDPARTY = 0x02, $SWC_CALLBACK = 0x04, $SWC_DESKTOP = 0x08 ; ShellWindowTypeConstants;
    Local Enum $SWFO_NEEDDISPATCH = 0x01, $SWFO_INCLUDEPENDING = 0x02, $SWFO_COOKIEPASSED = 0x04 ; ShellWindowFindWindowOptions;

    Local $pIDispatch, $oIDispatch
    Local $pIWebBrowserApp, $oIWebBrowserApp, $hWnd
    ; IShellWindows interface
    Local $oIShellWindows = ObjCreateInterface($CLSID_ShellWindows, $sIID_IShellWindows, $_dtag_IShellWindows)

    ;Find the desktop window in list of Shell Windows
    ConsoleWrite("FindWindowSW HRESULT 0x" & _
            Hex($oIShellWindows.FindWindowSW($CSIDL_DESKTOP, 0, $SWC_DESKTOP, $hWnd, $SWFO_NEEDDISPATCH, $pIDispatch)) & @CRLF)
    ConsoleWrite("Desktop hWnd = 0x" & Hex($hWnd) & @CRLF)

    If $pIDispatch Then
        $oIDispatch = ObjCreateInterface($pIDispatch, $sIID_IDispatch, $dtag_IDispatch)
        $oIDispatch.QueryInterface($tRIID_IWebBrowserApp, $pIWebBrowserApp)
        If $pIWebBrowserApp Then
            $oIWebBrowserApp = ObjCreateInterface($pIWebBrowserApp, $sIID_IWebBrowserApp, $dtag_IWebBrowserApp)
        EndIf
    EndIf

    ; IServiceProvider interface
    Local $pIServiceProvider, $oIServiceProvider
    $oIWebBrowserApp.QueryInterface($tRIID_IServiceProvider, $pIServiceProvider)
    $oIServiceProvider = ObjCreateInterface($pIServiceProvider, $sIID_IServiceProvider, $dtag_IServiceProvider)

    ; IShellBrowser interface
    Local $pIShellBrowser
    $oIServiceProvider.QueryService($tRIID_STopLevelBrowser, $tRIID_IShellBrowser, $pIShellBrowser)
    $oIShellBrowser = ObjCreateInterface($pIShellBrowser, $sIID_IShellBrowser, $dtag_IShellBrowser)
EndFunc   ;==>FindDesktopShellBrowser

Func ToggleDesktop($objShell)
    If IsObj($objShell) Then
        $objShell.ToggleDesktop
    EndIf
EndFunc   ;==>ToggleDesktop

 

Edited by Bilgus
Posted

Bilgus, Very interesting indeed. Quite a lot of the above items are about automating the desktop. So far, they have been unanswered. I'll look into the code after the Easter holiday.

Posted (edited)

Try as I might I couldn't seem to get FindWindowSw() to accept a PIDL for any KnownFolderIds

I figured it might be my error I even tried sequential numbers with a properly formatted tag_Variant and I couldn't get it to work

 

After searching on the net, I don't think it works for anyone else either so maybe its broken or the definition on MSDN is wrong

 

This works just fine for grabbing the desktop window

$oIShellWindows.FindWindowSW(NULL, NULL, $SWC_DESKTOP, $hWnd, $SWFO_NEEDDISPATCH, $pIDispatch)

 

So giving up on a way to find know folders I decided an EnumShellWindows() function would be the next best thing

  Reveal hidden contents

Do Note The populate Methods part won't be needed eventually but they are just there to make it work with the current example files

Edited by Bilgus
PathCreateFromUrlW($sLoc)
Posted (edited)

I updated the GetSetIconView example quite a bit It now lists all windows found with the above handy enum function 

Allows finding windows by Pidl(FolderIds)  The example uses CSIDL for ease of putting in a list but that function is depreciated

Adds a few functions from shlwapi and a some other misc stuff,

there are still some other parts I'm not particularly happy with but I'll probably save that for an update of my DeskViewChanger script

  Reveal hidden contents

SetIcons.png.6c84455a5560863dd5e034d50369bd9d.png

Edited by Bilgus
Posted

I haven't looked at the code yet, but I'm sure it's nice code.

I think it's possible to automate the standard Open/Save dialogs in similar ways. But I've not tried. Do you know about techniques to automate these dialogs?

  • 2 weeks later...
Posted

Playing with the interfaces for Dialogs for a few days I've come to the conclusion that you are only going to be able to access dialogs you create within your process.

 

Well I should say easily access,

I was able to get IUnknown from open/save as dialogs with AccessibleObjectFromWindow but The only interfaces exposed were IUnknown and IOleWindow so I've a feeling this is a dead end

 

For the next try I found a function SHShellFolderView_Message that is depreciated It gets IShellFolderView from another function 

that seems to be unexposed ShellFolderViewFromWindow and only used by the former depreciated function

This led me to an undocumented message CWM_GETISHELLBROWSER 

searching the net I found it as WM_GETISHELLBROWSER = WM_USER + 0x7 but very little info beyond that

 

Basically I was able to identify a window as having an IShellBrowser interface if there was a pointer returned

from SendMessage($hWnd, $WM_GETISHELLBROWSER, 0, 0) but it was a pointer within the host process therefore useless in its current form.

 

From what I can tell you would need to inject code into the host of the dialog to make use of the object returned by the call

to WM_GETISHELLBROWSER but that is as far as I've gotten thus far

 

 

  • 2 years later...
Posted

Hi,

Thank you for this great work. I'm new to this though and could do with a bit of help. I want to automate clicking on a mapped network drive in windows explorer. Do I open your GUI using AutoIt and use other AutoIt commands on your GUI window? If so I couldn't find how to automate clicking on the 'Browse' tab? Or can the commands be sent directly somehow? I'm not sure of the work flow. An example would be amazing.

Thank you,

A

Posted
  On 7/9/2020 at 8:21 AM, artyb said:

I want to automate clicking on a mapped network drive in windows explorer.

Expand  

This seems to be a completely normal automation task. If you're lucky, it can be done with the automation functions in the help file. The GUI in first post is just for demonstration of the features in the UDF. It cannot be used for your task. If you've more questions, ask them in the General Help and Support forum. Here you get much faster answers.

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...