devxlogo

Show the contents of the Recycle Bin folder

Show the contents of the Recycle Bin folder

You can use the ShellExecute API function to programmatically open a window of Explorer and display the contents of the Recycle Bin. This is the function’s declare:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _    (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _    ByVal lpParameters As String, ByVal lpDirectory As String, _    ByVal nShowCmd As Long) As Long

The first parameter is the handle of parent window, the second is the action to be peerformed (in our case is “open”), the third argument is the application to execute, the fourth is the command line for the application, the fifth is the default directory. The last specifies the style of the window (maximized, normal or minimized), and you can use the same constants accepted by VB’s Shell function. As you see in the following code, the trick is to specify the special GUID of the Recicly Bin in the command string passed to Explorer:

Private Sub cmdShowRecycleBin_Click()    ShellExecute 0, "Open", "explorer.exe", _        "/root,::{645FF040-5081-101B-9F08-00AA002F954E}", 0&, vbNormalFocusEnd Sub

The user can then select the Empty Recycle Bin command from the File menu to manually empty the Recycle Bin, if desired.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist