Sign in to follow this  
Followers 0
mbunds

How to launch Recycle Bin Properties?

5 posts in this topic

I wrote the following code using snippets from these forums to search the Windows Desktop (Progman) for the Recycle Bin, and right-click it to open the properties dialog.

Everything works perfectly UNLESS the Recycle Bin icon is covered by another window.

Debugging shows that the name of the icon is found in the Progman Listview no matter what, but the script just waits if the icon itself is covered up.

Running the script without anything covering the icon works every time.

Is there a more direct way to launch the Recycle Bin properties, or perhaps a way to "right click" the icon while it is hidden?

CODE
; Get the "Program Manager (Desktop)" ListView handle

$hList = ControlGetHandle("Program Manager", "", "SysListView321")

If @error Then MsgBox(4096,"Error","Unable to get desktop ListView handle")

; Find the Recycle Bin

$iIndex =_GUICtrlListView_FindText($hList, "Recycle Bin")

if $iIndex = -1 then

If @error Then MsgBox(4096,"Error","Recycle Bin Not Found")

endif

; Right click on the item

_GUICtrlListView_ClickItem($hList, $iIndex, "right", False, 1, 1)

send("r")

WinWait("Recycle Bin Properties","Global")

ControlClick("Recycle Bin Properties","Global","[CLASS:Button; INSTANCE:3]")

$hList = ControlGetHandle("Recycle Bin Properties","Global","[CLASS:Button; INSTANCE:4]"); Do not move files to recycle bin

$bst = _GUICtrlButton_GetCheck($hList)

if $bst = True THEN

;MsgBox(4096,"Checked","Button is checked")

ControlClick("Recycle Bin Properties","Global","[CLASS:Button; INSTANCE:4]")

Else

;MsgBox(4096,"Unchecked","Button is not checked")

EndIf

$hList = ControlGetHandle("Recycle Bin Properties","Global","[CLASS:Button; INSTANCE:5]")

$bst = _GUICtrlButton_GetCheck($hList)

if $bst = True THEN

;MsgBox(4096,"Checked","Button is checked")

Else

;MsgBox(4096,"Unchecked","Button is not checked")

ControlClick("Recycle Bin Properties","Global","[CLASS:Button; INSTANCE:5]")

EndIf

ControlClick("Recycle Bin Properties","Global","[CLASS:msctls_trackbar32; INSTANCE:1]");Set recycle bin slider to 1%

Send("{Left 100}")

Send("{Right}")

ControlClick("Recycle Bin Properties","Global","[CLASS:Button; INSTANCE:6]")

WinWaitClose("Recycle Bin Properties","Global")

Thanks in advance

Share this post


Link to post
Share on other sites



*Running the script without anything covering the icon works every time. *

WinMinimizeAll ( )

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

More clean solution:

_ShowFileProperties("::{645FF040-5081-101B-9F08-00AA002F954E}"); CLSID for recycle bin

Func _ShowFileProperties($sFile, $sVerb = "properties", $hWnd = 0)
;~   If Not FileExists($sFile) Then Return SetError(1, 0, 0); Doesn't work with CLSID
   
    Local Const $SEE_MASK_INVOKEIDLIST = 0xC
    Local Const $SEE_MASK_NOCLOSEPROCESS = 0x40
    Local Const $SEE_MASK_FLAG_NO_UI = 0x400
   
    Local $PropBuff, $FileBuff, $SHELLEXECUTEINFO
   
    $PropBuff = DllStructCreate("char[256]")
    DllStructSetData($PropBuff, 1, $sVerb)
   
    $FileBuff = DllStructCreate("char[256]")
    DllStructSetData($FileBuff, 1, $sFile)
   
    $SHELLEXECUTEINFO = DllStructCreate("int cbSize;long fMask;hwnd hWnd;ptr lpVerb;ptr lpFile;ptr lpParameters;ptr lpDirectory;" & _
                                        "int nShow;int hInstApp;ptr lpIDList;ptr lpClass;hwnd hkeyClass;int dwHotKey;hwnd hIcon;" & _
                                        "hwnd hProcess")
                                       
    DllStructSetData($SHELLEXECUTEINFO, "cbSize", DllStructGetSize($SHELLEXECUTEINFO))
    DllStructSetData($SHELLEXECUTEINFO, "fMask", $SEE_MASK_INVOKEIDLIST)
    DllStructSetData($SHELLEXECUTEINFO, "hwnd", $hWnd)
    DllStructSetData($SHELLEXECUTEINFO, "lpVerb", DllStructGetPtr($PropBuff, 1))
    DllStructSetData($SHELLEXECUTEINFO, "lpFile", DllStructGetPtr($FileBuff, 1))
   
    $aRet = DllCall("shell32.dll", "int", "ShellExecuteEx", "ptr", DllStructGetPtr($SHELLEXECUTEINFO))
    If $aRet[0] = 0 Then Return SetError(2, 0, 0)
   
;   Local $iPrevMode = Opt("WinTitleMatchMode", 2)
;   Local $iTitle = StringRegExpReplace($sFile, "^.*\\(.*)\..*", "\1")
   
;   WinWait($iTitle)
   
;   Do
;       Sleep(10)
;   Until WinExists($iTitle) = 0
   
;   Opt("WinTitleMatchMode", $iPrevMode)
   
    Return $aRet[0]
EndFunc

Credit to rasim for the function:

#565547

;)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

More clean solution:

_ShowFileProperties("::{645FF040-5081-101B-9F08-00AA002F954E}"); CLSID for recycle bin

Func _ShowFileProperties($sFile, $sVerb = "properties", $hWnd = 0)
;~   If Not FileExists($sFile) Then Return SetError(1, 0, 0); Doesn't work with CLSID
   
    Local Const $SEE_MASK_INVOKEIDLIST = 0xC
    Local Const $SEE_MASK_NOCLOSEPROCESS = 0x40
    Local Const $SEE_MASK_FLAG_NO_UI = 0x400
   
    Local $PropBuff, $FileBuff, $SHELLEXECUTEINFO
   
    $PropBuff = DllStructCreate("char[256]")
    DllStructSetData($PropBuff, 1, $sVerb)
   
    $FileBuff = DllStructCreate("char[256]")
    DllStructSetData($FileBuff, 1, $sFile)
   
    $SHELLEXECUTEINFO = DllStructCreate("int cbSize;long fMask;hwnd hWnd;ptr lpVerb;ptr lpFile;ptr lpParameters;ptr lpDirectory;" & _
                                        "int nShow;int hInstApp;ptr lpIDList;ptr lpClass;hwnd hkeyClass;int dwHotKey;hwnd hIcon;" & _
                                        "hwnd hProcess")
                                       
    DllStructSetData($SHELLEXECUTEINFO, "cbSize", DllStructGetSize($SHELLEXECUTEINFO))
    DllStructSetData($SHELLEXECUTEINFO, "fMask", $SEE_MASK_INVOKEIDLIST)
    DllStructSetData($SHELLEXECUTEINFO, "hwnd", $hWnd)
    DllStructSetData($SHELLEXECUTEINFO, "lpVerb", DllStructGetPtr($PropBuff, 1))
    DllStructSetData($SHELLEXECUTEINFO, "lpFile", DllStructGetPtr($FileBuff, 1))
   
    $aRet = DllCall("shell32.dll", "int", "ShellExecuteEx", "ptr", DllStructGetPtr($SHELLEXECUTEINFO))
    If $aRet[0] = 0 Then Return SetError(2, 0, 0)
   
;   Local $iPrevMode = Opt("WinTitleMatchMode", 2)
;   Local $iTitle = StringRegExpReplace($sFile, "^.*\\(.*)\..*", "\1")
   
;   WinWait($iTitle)
   
;   Do
;       Sleep(10)
;   Until WinExists($iTitle) = 0
   
;   Opt("WinTitleMatchMode", $iPrevMode)
   
    Return $aRet[0]
EndFunc

Credit to rasim for the function:

#565547

;)

This is certainly the type of solution I was looking for, but it doesn't seem to work with the CLSID directly. I thank you kindly and I'll see if I can find some way to make it work!

Share this post


Link to post
Share on other sites

Thanks millions, monoceres!

After I uncommented the following two lines, the routine worked perfectly!

; Local $iPrevMode = Opt("WinTitleMatchMode", 2)

; Local $iTitle = StringRegExpReplace($sFile, "^.*\\(.*)\..*", "\1")

Credit to rasim for the function:

#565547

:D

I really appreciate the time the brilliant people on this forum share to help us noobs work through the rough spots!

Thanks again! ;)

Share this post


Link to post
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
Sign in to follow this  
Followers 0