Results 1 to 4 of 4

Thread: Restoring recycle bin files from VB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    129

    Lightbulb Restoring recycle bin files from VB

    Simple question that I cant figure out --

    How to restore ALL recycle bin items from VB code.

    Thanks all.

    BaLLZaCH
    [email protected]
    VB5 and VB6
    BaLLZaCH

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    You can only do the following with the recycle bin...

    • Empty it
    • Query it (see how much space it consumes)
    • Update the icon (e.g. if you deleted everything in it, you'd need to update the icon to show the bin empty)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    129
    Sweet bud, I didnt know that ...


    Can you instruct me on how to empty the bin with vb code ?

    Thanks bro.
    BaLLZaCH

  4. #4
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Sure thing bro...paste this into the declarations section of a form
    VB Code:
    1. Const SHERB_NOCONFIRMATION = &H1
    2. Const SHERB_NOPROGRESSUI = &H2
    3. Const SHERB_NOSOUND = &H4
    4.  
    5. Private Type ULARGE_INTEGER
    6.   LowPart As Long
    7.   HighPart As Long
    8. End Type
    9.  
    10. Private Type SHQUERYRBINFO
    11.   cbSize As Long
    12.   i64Size As ULARGE_INTEGER
    13.   i64NumItems As ULARGE_INTEGER
    14. End Type
    15.  
    16. Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
    17. Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Long
    18. Private Declare Function SHQueryRecycleBin Lib "shell32.dll" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, pSHQueryRBInfo As SHQUERYRBINFO) As Long
    19. Private Sub Form_Load()
    20.  
    21. Dim RBinInfo As SHQUERYRBINFO
    22. Dim Msg As VbMsgBoxResult
    23.    
    24. RBinInfo.cbSize = Len(RBinInfo)
    25. SHQueryRecycleBin vbNullString, RBinInfo
    26.    
    27. If (RBinInfo.i64Size.LowPart And &H80000000) = &H80000000 Or RBinInfo.i64Size.HighPart > 0 Then
    28.     Msg = MsgBox("Your Recycle Bin consumes over 2 gigabytes right now!" + vbCrLf + "Do you want to empty it?", vbYesNo + vbQuestion)
    29. Else
    30.     Msg = MsgBox("Your Recycle Bin consumes" + Str$(RBinInfo.i64Size.LowPart) + " bytes right now." + vbCrLf + "Do you want to empty it?", vbYesNo + vbQuestion)
    31. End If
    32.    
    33. If Msg = vbYes Then
    34.     SHEmptyRecycleBin Me.hwnd, vbNullString, 0
    35.     SHUpdateRecycleBinIcon
    36. End If
    37.  
    38. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width