; ; === Functions === ; ; Get Windows Explorer interface objects ; GetIShellBrowser ; GetShellInterfaces ; IsNewShellFolder ; ; Get/set information in Windows Explorer ; GetCurrentFolder ; SetCurrentFolder ; ; CountItems ; GetItems ; GetFiles ; GetFolders ; GetPidls ; GetFocusedItem ; ; SetFocusedItem ; SetSelectedItem ; ; GetIconView ; SetIconView ; ; === Helper functions === ; GetDisplayNameAbs ; GetDisplayNameRel ; GetParsingNameRel ; ; === Internal functions === ; ; GetExplorerItems ; GetExplorerItemsByType ; GetExplorerPidls ; ; === Free memory === ; ; Depending on parameters most functions can return PIDLs. Some functions return only PIDLs. In these cases ; you must free memory (_WinAPI_CoTaskMemFree) used by the PIDLs, when you have finished using the PIDLs. ; #cs https://msdn.microsoft.com/en-us/library/windows/desktop/bb762548(v=vs.85).aspx typedef enum _SVGIO { SVGIO_BACKGROUND = 0x00000000, SVGIO_SELECTION = 0x00000001, SVGIO_ALLVIEW = 0x00000002, SVGIO_CHECKED = 0x00000003, SVGIO_TYPE_MASK = 0x0000000F, SVGIO_FLAG_VIEWORDER = 0x80000000 } _SVGIO; https://msdn.microsoft.com/en-us/library/windows/desktop/dd378455(v=vs.85).aspx typedef enum _SVSIF { SVSI_DESELECT = 0x00000000, SVSI_SELECT = 0x00000001, SVSI_EDIT = 0x00000003, SVSI_DESELECTOTHERS = 0x00000004, SVSI_ENSUREVISIBLE = 0x00000008, SVSI_FOCUSED = 0x00000010, SVSI_TRANSLATEPT = 0x00000020, SVSI_SELECTIONMARK = 0x00000040, SVSI_POSITIONITEM = 0x00000080, SVSI_CHECK = 0x00000100, SVSI_CHECK2 = 0x00000200, SVSI_KEYBOARDSELECT = 0x00000401, SVSI_NOTAKEFOCUS = 0x40000000 } _SVSIF; #ce #RequireAdmin ; Runs script as admin user #include-once #include #include #include #include #include ; #Include <_DBUG.au3> ; Used for debugging script Global $oIShellBrowser, $pIShellView, $oIShellView, $oIFolderView, $oIFolderView2, $oIPersistFolder2, $oIShellFolder ;$filename = "e:\users\davida\desktop\test.txt" ;GetFileFocus($filename) ;$folderpath = "e:\users\davida\desktop\ASUS" ;GetFolderFocus($folderpath) Func GetFileFocus($wantedFile) ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface Local $hObject = GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer - 1", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get all files with full path ; GetFiles( $fSelected = False, $fFullPath = True, $fPidl = False, $iMax = 0 ) ; GetItems returns $aFileList Local $aFileList = GetItems( False, True, True ) ;_ArrayDisplay( $aFileList, "aFiles list" ) Local $iRows = UBound($aFileList, $UBOUND_ROWS) ; Total number of rows. Local $afoundit = False For $i=0 To $iRows - 1 If $aFileList[$i][0] = $wantedFile Then $afoundit = True $saveI = $i ; IFolderView.SelectItem selects an item in the folder's view. ; If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. Local $aReturn = $oIFolderView.SelectItem( $i, $SVSI_SELECT) ;Local $a1Return = $oIFolderView.SelectItem( $i, $SVSI_FOCUSED ) If ($aReturn = $S_OK ) Then ; worked - continue On Else MsgBox(0, "$oIFolderView.SelectItem failed ", "$aReturn:" & $aReturn) Return EndIf Else ; deselect item in case multiple things are selected Local $bReturn = $oIFolderView.SelectItem( $i, $SVSI_DESELECT ) If $bReturn = $S_OK Then ; worked - continue On Else MsgBox(0, "$oIFolderView.SelectItem failed ", $bReturn) Return EndIf EndIf Next If $afoundit = False Then MsgBox(0, "Wanted Item Not Found ", "bReturn: " & $bReturn) MsgBox(0, "$afilelist[" & $i & "][0]=", $aFileList[$i-1][0]) MsgBox(0, "$wantedFile=", $wantedFile) _ArrayDisplay( $aFileList, "Selected files" ) Return EndIf ;_ArrayDisplay( $aFileList, "Selected files" ) Return $saveI EndFunc ;--> GetFileFocus Func GetFolderFocus($folderpath) ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface Local $hObject = GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer - 2", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get all folders with full path ; returns pointer to folder ; GetFolders( $fSelected = False, $fFullPath = True, $fPidl = False, $iMax = 0 ) Local $aFolderList = GetItems( False, True, True) Local $cReturn Local $dReturn ;_ArrayDisplay( $aFolderList, "aFolderList" ) Local $iRows = UBound($aFolderList, $UBOUND_ROWS) ; Total number of rows. Local $bfoundit = False For $i=0 To $iRows - 1 If $aFolderList[$i][0] = $folderpath Then $bfoundit = True $cReturn = $oIFolderView.SelectItem( $i, $SVSI_FOCUSED ) If $cReturn = $S_OK Then ; worked - continue On Else MsgBox(0, "$oIFolderView.SelectItem failed ", "cReturn:" & $cReturn & @CRLF) Return EndIf Else ; deselect item in case multiple things are selected $dReturn = $oIFolderView.SelectItem( $i, $SVSI_DESELECT ) If $dReturn = $S_OK Then ; worked - continue On Else MsgBox(0, "$oIFolderView.SelectItem failed ", "dReturn:" & $dReturn & @CRLF) Return EndIf EndIf Next If $bfoundit = False Then MsgBox(0, "Wanted Item Not Found", "cReturn: dReturn:", $cReturn & " " & $dReturn & @CRLF) MsgBox(0, "$aFolderList[" & $i & "][0]=", $aFolderList[$i-1][0]) MsgBox(0, "$folderpath= ", $folderpath) _ArrayDisplay( $aFolderList, "Selected files" ) Return EndIf EndFunc ;--> GetFolderFocus Func GetIShellBrowser( $hExplorer ) ; IShellBrowser Windows interface - looks at open browser windows and selects one equal to $hExplorer Local $pIShellWindows, $oIShellWindows ; CoCreateInstance Creates a single uninitialized object of the class associated with a specified CLSID ; CLSID CLSID_ShellWindows (9BA05972-F6A8-11CF-A442-00A0C90A8F39) ; $tCLSID_ShellWindows The CLSID associated with the data and code that will be used to create the object ; IID IID_IShellWindows (85CB6900-4D95-11CF-960C-0080C7F4EE85) ; $tRIID_IShellWindows reference to the identifier of the interface to be used to communicate with the object ; If NULL, indicates that the object is not being created as part of an aggregate. ; $CLSCTX_ALL is defined as the type of server used to manage the object and is combination of all four ; (CLSCTX_INPROC_SERVER, CLSCTX_INPROC_HANDLER, CLSCTX_LOCAL_SERVER, CLSCTX_REMOTE_SERVER) ; $pIShellWindows Address of pointer variable that receives the interface pointer requested in riid CoCreateInstance( $tCLSID_ShellWindows, $NULL, $CLSCTX_ALL, $tRIID_IShellWindows, $pIShellWindows ) $oIShellWindows = ObjCreateInterface( $pIShellWindows, $sIID_IShellWindows, $dtag_IShellWindows ) ; Number of shell windows Local $iWindows $oIShellWindows.get_Count( $iWindows ) ; Gets the number of windows in the Shell windows collection ; Get an IWebBrowserApp object for each window ; This is done in two steps: ; 1. Get an IDispatch object for the window ; 2. Get the IWebBrowserApp interface ; Check if it's the right window Local $pIDispatch, $oIDispatch Local $pIWebBrowserApp, $oIWebBrowserApp, $hWnd For $i = 0 To $iWindows - 1 $oIShellWindows.Item( $i, $pIDispatch ) ; Returns the registered Shell window for a specified index $i If $pIDispatch Then ; A ptr reference to the window's IDispatch interface, or NULL if the specified window was not found. $oIDispatch = ObjCreateInterface( $pIDispatch, $sIID_IDispatch, $dtag_IDispatch ) ; Creates a reference to an object ; from the given classname/object pointer $oIDispatch.QueryInterface( $tRIID_IWebBrowserApp, $pIWebBrowserApp ) ; QueryInterface checks whether the object supports IDispatch. If $pIWebBrowserApp Then $oIWebBrowserApp = ObjCreateInterface( $pIWebBrowserApp, $sIID_IWebBrowserApp, $dtag_IWebBrowserApp ) $oIWebBrowserApp.get_HWND( $hWnd ) ; Gets the window handle, HWND, associated with the Class object If $hWnd = $hExplorer Then ExitLoop EndIf EndIf Next ; IServiceProvider interface Local $pIServiceProvider, $oIServiceProvider $oIWebBrowserApp.QueryInterface( $tRIID_IServiceProvider, $pIServiceProvider ) ; returns a new pointer to the requested interface $oIServiceProvider = ObjCreateInterface( $pIServiceProvider, $sIID_IServiceProvider, $dtag_IServiceProvider ) ; IShellBrowser interface ; QueryService creates or accesses the implementation of the service identified with guidService. ; In ppv, it returns the address of the interface that is specified by riid. Local $pIShellBrowser $oIServiceProvider.QueryService( $tRIID_STopLevelBrowser, $tRIID_IShellBrowser, $pIShellBrowser ) $oIShellBrowser = ObjCreateInterface( $pIShellBrowser, $sIID_IShellBrowser, $dtag_IShellBrowser ) EndFunc ;--> GetIShellBrowser Func GetShellInterfaces() Local $pIFolderView, $pIFolderView2, $pIPersistFolder2, $pIShellFolder, $pPidlFolder, $pPidlRel, $i = 0 ; IShellView interface $oIShellBrowser.QueryActiveShellView( $pIShellView ) ; Retrieves The address of the pointer to the currently active (displayed) Shell view object. $oIShellView = ObjCreateInterface( $pIShellView, $sIID_IShellView, $dtag_IShellView ) ; Creates a reference to an object from the given classname/object pointer ; IFolderView interface $oIShellView.QueryInterface( $tRIID_IFolderView, $pIFolderView ) ; returns a new pointer to the requested interface ; A special instance of IShellView known as the default Shell folder view object can be created by calling SHCreateShellFolderView or SHCreateShellFolderViewEx. This instance can be differentiated from standard implementations by calling QueryInterface on an IShellView object using the IID_CDefView IID. This call succeeds only when made on the default Shell folder view object. $oIFolderView = ObjCreateInterface( $pIFolderView, $sIID_IFolderView, $dtag_IFolderView ) ; Creates a reference to an object from the given classname/object pointer If @OSVersion <> "WIN_XP" Then ; IFolderView2 interface (Vista and later) $oIShellView.QueryInterface( $tRIID_IFolderView2, $pIFolderView2 ) $oIFolderView2 = ObjCreateInterface( $pIFolderView2, $sIID_IFolderView2, $dtag_IFolderView2 ) EndIf ; IPersistFolder2 interface $oIFolderView.GetFolder( $tRIID_IPersistFolder2, $pIPersistFolder2 ) ; Reference to the desired IID to represent the folder and returns interface pointer requested in riid $oIPersistFolder2 = ObjCreateInterface( $pIPersistFolder2, $sIID_IPersistFolder2, $dtag_IPersistFolder2 ) $oIPersistFolder2.GetCurFolder( $pPidlFolder ) ; Gets address of an ITEMIDLIST pointer for the folder object ; IShellFolder interface If ILIsEqual( $pPidlFolder, $pPidlAbsDesktop ) Then ; Tests whether two ITEMIDLIST structures are equal in a binary comparison SHGetDesktopFolder( $pIShellFolder ) ; Retrieves the IShellFolder interface for the desktop folder, which is the root of the Shell's namespace Else Local $pIParentFolder, $oIParentFolder, $pPidlRel SHBindToParent( $pPidlFolder, DllStructGetPtr( $tRIID_IShellFolder ), $pIParentFolder, $pPidlRel ) ; Takes a pointer to a fully qualified item identifier list (PIDL), and returns a specified interface pointer on the parent object $oIParentFolder = ObjCreateInterface( $pIParentFolder, $sIID_IShellFolder, $dtag_IShellFolder ) $oIParentFolder.BindToObject( $pPidlRel, $NULL, $tRIID_IShellFolder, $pIShellFolder ) ; Retrieves a handler, typically the Shell folder object that implements IShellFolder for a particular item EndIf $oIShellFolder = ObjCreateInterface( $pIShellFolder, $sIID_IShellFolder, $dtag_IShellFolder ) ; Free memory used by $pPidlFolder _WinAPI_CoTaskMemFree( $pPidlFolder ) ; Wait for Explorer to refresh $pPidlRel = GetFocusedItem() While Not $pPidlRel And $i < 10 ; check for focused item Sleep( 25 ) $pPidlRel = GetFocusedItem() $i += 1 WEnd ; Free memory used by $pPidlRel If $pPidlRel Then _ _WinAPI_CoTaskMemFree( $pPidlRel ) EndFunc ;--> GetShellInterfaces Func IsNewShellFolder() ; For a new folder, we'll get a new ; pointer for the IShellView interface. Local $pIShellViewNew, $i = 0 $oIShellBrowser.QueryActiveShellView( $pIShellViewNew ) ; The address of the pointer to the currently active Shell view object ; Wait for Explorer to refresh While $pIShellViewNew = $pIShellView And $i < 10 Sleep( 10 ) $oIShellBrowser.QueryActiveShellView( $pIShellViewNew ) $i += 1 WEnd Return ( $pIShellViewNew <> $pIShellView ) ; is the new folder same as the current one? returns T or F EndFunc ;--> IsNewShellFolder ; --- Get/set information in Windows Explorer --- ; For examples search the functions in Example.au3 and Example\*.au3. Func GetCurrentFolder() Local $pPidlAbs $oIPersistFolder2.GetCurFolder( $pPidlAbs ) Return $pPidlAbs EndFunc ;--> GetCurrentFolder ; After this command $oIShellBrowser is the only valid interface object. To ; be able to use the other interfaces you must execute GetShellInterfaces(). Func SetCurrentFolder( $pPidl, $fFlag ) $oIShellBrowser.BrowseObject( $pPidl, BitOR( $SBSP_DEFBROWSER, $fFlag ) ) EndFunc ;--> SetCurrentFolder Func CountItems( $fSelected = False ) Local $iCount, $fSelection = $fSelected ? $SVGIO_SELECTION : $SVGIO_ALLVIEW ; SVGIO_SELECTION=0x00000001 / SVGIO_ALLVIEW=0x00000002 $oIFolderView.ItemCount( $fSelection, $iCount ) Return $iCount EndFunc ;--> CountItems Func GetItems( $fSelected = False, $fFullPath = True, $fPidl = False, $iMax = 0 ) Local $fSelection = $fSelected ? $SVGIO_SELECTION : $SVGIO_ALLVIEW Local $aItems, $fItemName = $fFullPath ? $SHGDN_FORPARSING : $SHGDN_NORMAL ; Func GetExplorerItems( $oIFolderView, $oIShellFolder, $fSelection, $fName, ByRef $aItems, $fFullPath = True, $fPidl = False, $iMax = 0 ) GetExplorerItems( $oIFolderView, $oIShellFolder, $fSelection, $fItemName, $aItems, $fFullPath = True, $fPidl, $iMax ) Return $aItems EndFunc ;--> GetItems Func GetFiles( $fSelected = False, $fFullPath = True, $fPidl = False, $iMax = 0 ) Local $fSelection = $fSelected ? $SVGIO_SELECTION : $SVGIO_ALLVIEW Local $aItems, $fItemName = $fFullPath ? $SHGDN_FORPARSING : $SHGDN_NORMAL ; Func GetExplorerItems( $oIFolderView, $oIShellFolder, $fSelection, $fName, ByRef $aItems, $fFullPath = True, $fPidl = False, $iMax = 0 ) GetExplorerItemsByType( $oIFolderView, $oIShellFolder, $fSelection, $fItemName, $aItems, $fFullPath, $fPidl, $iMax ) Return $aItems EndFunc ;--> GetFiles Func GetFolders( $fSelected = False, $fFullPath = True, $fPidl = False, $iMax = 0 ) Local $fSelection = $fSelected ? $SVGIO_SELECTION : $SVGIO_ALLVIEW Local $aItems, $fItemName = $fFullPath ? $SHGDN_FORPARSING : $SHGDN_NORMAL ; Func GetExplorerItemsByType( $oIFolderView, $oIShellFolder, $fSelection, $fName, ByRef $aItems, $fFiles = False, $fFullPath = True, $fPidl = False, $iMax = 0 ) GetExplorerItemsByType( $oIFolderView, $oIShellFolder, $fSelection, $fItemName, $aItems, $fFiles, $fFullPath, $fPidl, $iMax ) Return $aItems EndFunc ;--> GetFolders ; This function is much faster than the three functions above, because the names are not calculated. ; The function does not distinguish between files and folders, it gets all pidls or all selected pidls. Func GetPidls( $fSelected = False ) Local $aPidls, $fSelection = $fSelected ? $SVGIO_SELECTION : $SVGIO_ALLVIEW GetExplorerPidls( $oIFolderView, $oIShellFolder, $fSelection, $aPidls ) Return $aPidls EndFunc ;--> GetPidls Func GetFocusedItem() ; returns the identifier ptr of the focused item Local $iFocus, $pPidlRel $oIFolderView.GetFocusedItem( $iFocus ) ; Gets the index of the item that currently has focus in the folder's view If $iFocus = -1 Then Return 0 $oIFolderView.Item( $iFocus, $pPidlRel ) ; Gets the identifier of a specific item in the folder view, by index Return $pPidlRel EndFunc ;--> GetFocusedItem Func SetFocusedItem( $item, $fPidl = False ) ; iItem Type: int The index of the item to select in the folder's view. If $fPidl Then ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd378455(v=vs.85).aspx $oIShellView.SelectItem( $item, $SVSI_FOCUSED ) ; $item = $pPidlRel Else $oIFolderView.SelectItem( $item, $SVSI_FOCUSED ) ; $item = $iIndex EndIf EndFunc ;--> SetFocusedItem Func SetSelectedItem( $item, $fSelected = True, $fPidl = False ) Local $fSelection = $fSelected ? $SVSI_SELECT : $SVSI_DESELECT If $fPidl Then $oIShellView.SelectItem( $item, $fSelection ) ; $item = $pPidlRel Else $oIFolderView.SelectItem( $item, $fSelection ) ; $item = $iIndex EndIf EndFunc ;--> SetSelectedItem Func GetIconView() Local $iViewMode, $iIconSize If @OSVersion = "WIN_XP" Then $oIFolderView.GetCurrentViewMode( $iViewMode ) Return $iViewMode Else $oIFolderView2.GetViewModeAndIconSize( $iViewMode, $iIconSize ) Local $aView = [ $iViewMode, $iIconSize ] Return $aView EndIf EndFunc ;--> GetIconView Func SetIconView( $iViewMode, $iIconSize = 0 ) If @OSVersion = "WIN_XP" Then $oIFolderView.SetCurrentViewMode( $iViewMode ) Else $oIFolderView2.SetViewModeAndIconSize( $iViewMode, $iIconSize ) EndIf EndFunc ;--> SetIconView ; --- Helper functions --- ; For examples search Example.au3 and Example\*.au3. ; Returns a nice name (not full path) relative to Desk- ; top - without GUID-strings for system files/folders. ; $pPidlAbs must be a child PIDL relative to Desktop. ; (A child PIDL relative to Desktop is also absolut.) Func GetDisplayNameAbs( $pPidlAbs ) Local Static $pIDesktopFolder, $oIDesktopFolder If Not $pIDesktopFolder Then SHGetDesktopFolder( $pIDesktopFolder ) $oIDesktopFolder = ObjCreateInterface( $pIDesktopFolder, $sIID_IShellFolder, $dtag_IShellFolder ) EndIf ; Note that this code is the same as the code below, ; just $oIDesktopFolder instead of $oIShellFolder. Local $tSTRRET = DllStructCreate( $tagSTRRET ), $sName $oIDesktopFolder.GetDisplayNameOf( $pPidlAbs, $SHGDN_NORMAL, $tSTRRET ) StrRetToBuf( DllStructGetPtr( $tSTRRET ), $NULL, $sName ) Return $sName EndFunc ;--> GetDisplayNameAbs ; Returns a nice name (not full path) relative to current ; folder - without GUID-strings for system files/folders. Func GetDisplayNameRel( $pPidlRel ) ; Note that this code is the same as the code above, ; just $oIShellFolder instead of $oIDesktopFolder. Local $tSTRRET = DllStructCreate( $tagSTRRET ), $sName $oIShellFolder.GetDisplayNameOf( $pPidlRel, $SHGDN_NORMAL, $tSTRRET ) StrRetToBuf( DllStructGetPtr( $tSTRRET ), $NULL, $sName ) Return $sName EndFunc ;--> GetDisplayNameRel ; Returns the full path for a file/folder. Can ; include GUID-strings for system files/folders. Func GetParsingNameRel( $pPidlRel ) ; Note that this code is the same as the code above, ; just $SHGDN_FORPARSING instead of $SHGDN_NORMAL. Local $tSTRRET = DllStructCreate( $tagSTRRET ), $sName $oIShellFolder.GetDisplayNameOf( $pPidlRel, $SHGDN_FORPARSING, $tSTRRET ) StrRetToBuf( DllStructGetPtr( $tSTRRET ), $NULL, $sName ) Return $sName EndFunc ;--> GetParsingNameRel ; --- Internal functions --- ; You can call these functions directly, but you have to take care of all the parameters, which includes ; interface objects and constants like $SVGIO_ALLVIEW, $SVGIO_SELECTION, $SHGDN_NORMAL and $SHGDN_FORPARSING. ; Retrieve all/selected items ; $fSelection = $SVGIO_ALLVIEW/$SVGIO_SELECTION ; $fName = $SHGDN_NORMAL/$SHGDN_FORPARSING Func GetExplorerItems( $oIFolderView, $oIShellFolder, $fSelection, $fName, ByRef $aItems, $fFullPath = True, $fPidl = False, $iMax = 0 ) ; Number of items Local $iItems $fSelection = BitOR( $fSelection, $SVGIO_FLAG_VIEWORDER ) $oIFolderView.ItemCount( $fSelection, $iItems ) If $iItems = 0 Then Return 0 Hourglass( True ) If $iMax Then If $iItems > $iMax Then $iItems = $iMax Else $iMax = $iItems EndIf Else $iMax = $iItems EndIf ; Enumeration object Local $pIEnumIDList, $oIEnumIDList $oIFolderView.Items( $fSelection, $tRIID_IEnumIDList, $pIEnumIDList ) $oIEnumIDList = ObjCreateInterface( $pIEnumIDList, $sIID_IEnumIDList, $dtag_IEnumIDList ) ; Name format If Not $fFullPath Then If $fName = $SHGDN_NORMAL Then $fName = $SHGDN_INFOLDER Else ; $fName = $SHGDN_FORPARSING $fName = BitOr( $SHGDN_INFOLDER, $SHGDN_FORPARSING ) EndIf EndIf Local $aItemsAr[$iMax], $pidlRel, $iFetched, $n = 0 If $fPidl Then ReDim $aItemsAr[$iMax][2] ; DllStructCreate Creates a C/C++ style structure to be used in DllCall. Local $tSTRRET = DllStructCreate( $tagSTRRET ), $sName While $oIEnumIDList.Next( 1, $pidlRel, $iFetched ) = $S_OK And $n < $iMax ; IEnumIDList.Next - Exposes a standard set of methods used to enumerate the pointers to item identifier lists (PIDLs) of the items in a Shell folder. ; When a folder's IShellFolder::EnumObjects method is called, it creates an enumeration object and passes a pointer to the object's IEnumIDList ; interface back to the calling application. ; Next - Retrieves the specified number of item identifiers in the enumeration sequence and advances the current position by the number of items retrieved. ; S_OK Operation successful 0x00000000 $oIShellFolder.GetDisplayNameOf( $pidlRel, $fName, $tSTRRET ) ; StrRetToBuf Converts an STRRET structure returned by IShellFolder::GetDisplayNameOf to a string, and places the result in a buffer. ; DllStructGetPtr Returns the pointer to the struct or an element in the struct. StrRetToBuf( DllStructGetPtr( $tSTRRET ), $NULL, $sName ) If $fPidl Then $aItemsAr[$n][0] = $sName $aItemsAr[$n][1] = $pidlRel Else _WinAPI_CoTaskMemFree( $pidlRel ) $aItemsAr[$n] = $sName EndIf $n += 1 WEnd Hourglass( False ) $aItems = $aItemsAr Return $iItems EndFunc ;--> GetExplorerItems ; Retrieve all/selected items by type ; $fSelection = $SVGIO_ALLVIEW/$SVGIO_SELECTION ; $fName = $SHGDN_NORMAL/$SHGDN_FORPARSING ; Get items by type: $fFiles = True/False Func GetExplorerItemsByType( $oIFolderView, $oIShellFolder, $fSelection, $fName, ByRef $aItems, $fFiles = True, $fFullPath = True, $fPidl = False, $iMax = 0 ) ; Number of items Local $iItems $fSelection = BitOR( $fSelection, $SVGIO_FLAG_VIEWORDER ) $oIFolderView.ItemCount( $fSelection, $iItems ) If $iItems = 0 Then Return 0 Hourglass( True ) If $iMax Then If $iItems > $iMax Then $iItems = $iMax Else $iMax = $iItems EndIf Else $iMax = $iItems EndIf ; Enumeration object Local $pIEnumIDList, $oIEnumIDList $oIFolderView.Items( $fSelection, $tRIID_IEnumIDList, $pIEnumIDList ) ; Gets the address of an enumeration object based on the collection of items in the folder view $oIEnumIDList = ObjCreateInterface( $pIEnumIDList, $sIID_IEnumIDList, $dtag_IEnumIDList ) ; Name format If Not $fFullPath Then If $fName = $SHGDN_NORMAL Then $fName = $SHGDN_INFOLDER Else ; $fName = $SHGDN_FORPARSING $fName = BitOr( $SHGDN_INFOLDER, $SHGDN_FORPARSING ) EndIf EndIf ; Get Explorer items Local $aItemsAr[$iMax], $pidlRel, $iFetched, $n = 0 If $fPidl Then ReDim $aItemsAr[$iMax][2] Local $tSTRRET = DllStructCreate( $tagSTRRET ), $sName Local $tArray = DllStructCreate( "ptr" ), $iAttribs While $oIEnumIDList.Next( 1, $pidlRel, $iFetched ) = $S_OK And $n < $iMax DllStructSetData( $tArray, 1, $pidlRel ) $iAttribs = BitOR( $SFGAO_FOLDER, $SFGAO_STREAM ) $oIShellFolder.GetAttributesOf( 1, $tArray, $iAttribs ) ; Attributes that can be retrieved on an item (file or folder) or set of items. If BitAND( $iAttribs, $SFGAO_FOLDER ) And Not BitAND( $iAttribs, $SFGAO_STREAM ) Then ; Item is a folder If $fFiles Then _WinAPI_CoTaskMemFree( $pidlRel ) ContinueLoop EndIf Else ; Item is a file If Not $fFiles Then _WinAPI_CoTaskMemFree( $pidlRel ) ContinueLoop EndIf EndIf $oIShellFolder.GetDisplayNameOf( $pidlRel, $fName, $tSTRRET ) ; Retrieves the display name for the specified file object or subfolder. StrRetToBuf( DllStructGetPtr( $tSTRRET ), $NULL, $sName ) ; Returns the pointer to the struct or an element in the struct. If $fPidl Then $aItemsAr[$n][0] = $sName $aItemsAr[$n][1] = $pidlRel Else _WinAPI_CoTaskMemFree( $pidlRel ) $aItemsAr[$n] = $sName EndIf $n += 1 WEnd Hourglass( False ) If $fPidl Then ReDim $aItemsAr[$n][2] Else ReDim $aItemsAr[$n] EndIf $aItems = $aItemsAr Return $iItems EndFunc ; --> GetExplorerItemsByType ; Retrieve all/selected pidls ; $fSelection = $SVGIO_ALLVIEW/$SVGIO_SELECTION ; This function is much faster than the two functions above, because the names are not calculated Func GetExplorerPidls( $oIFolderView, $oIShellFolder, $fSelection, ByRef $aPidls ) ; Number of pidls Local $iPidls $fSelection = BitOR( $fSelection, $SVGIO_FLAG_VIEWORDER ) $oIFolderView.ItemCount( $fSelection, $iPidls ) If $iPidls = 0 Then Return 0 Hourglass( True ) ; Enumeration object Local $pIEnumIDList, $oIEnumIDList $oIFolderView.Items( $fSelection, $tRIID_IEnumIDList, $pIEnumIDList ) $oIEnumIDList = ObjCreateInterface( $pIEnumIDList, $sIID_IEnumIDList, $dtag_IEnumIDList ) Local $aPidlsAr[$iPidls], $pidlRel, $iFetched, $n = 0 While $oIEnumIDList.Next( 1, $pidlRel, $iFetched ) = $S_OK $aPidlsAr[$n] = $pidlRel $n += 1 WEnd Hourglass( False ) $aPidls = $aPidlsAr Return $iPidls EndFunc ;--> GetExplorerPidls