I've got some old code of mine that I'm going back to and updating a little bit. On one part of it I need to check if there are any items in the recycle bin or not.

This is the code I was using to accomplish this:

vbcode Code:
  1. Private Declare Function SHQueryRecycleBin Lib "shell32.dll" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, ByRef pSHQueryRBInfo As SHQUERYRBINFO) As Long
  2.     Private Structure ULARGE_INTEGER
  3.         Dim LowPart As Integer
  4.         Dim HighPart As Integer
  5.     End Structure
  6.     Private Structure SHQUERYRBINFO
  7.         Dim cbSize As Integer
  8.         Dim i64Size As ULARGE_INTEGER
  9.         Dim i64NumItems As ULARGE_INTEGER
  10.     End Structure
  11.     Public Function IsRecycleBinEmpty() As Boolean
  12.         Dim SHQBI As SHQUERYRBINFO
  13.  
  14.         SHQBI.cbSize = Marshal.SizeOf(SHQBI)
  15.         SHQueryRecycleBin("", SHQBI)
  16.  
  17.         If (SHQBI.i64Size.LowPart <> LastRecycleBinSize) Then
  18.             MsgBox(SHQBI.i64Size.HighPart.ToString + " - " + SHQBI.i64Size.LowPart.ToString + " - " + SHQBI.i64NumItems.LowPart.ToString + " - " + SHQBI.i64NumItems.HighPart.ToString)
  19.             LastRecycleBinSize = SHQBI.i64Size.LowPart
  20.         End If
  21.         End
  22.  
  23.         If (SHQBI.i64NumItems.LowPart) Then
  24.             IsRecycleBinEmpty = False
  25.         Else
  26.             IsRecycleBinEmpty = True
  27.         End If
  28.     End Function

The msgbox and end is just in there for debugging purposes. This always returns all 0s, even when I know that there is something in the recycle bin.

Anyone have any ideas on what I'm doing wrong here?

Thanks!