Solved

Empty Recyle Bin problem

Posted on 2002-07-25
9
356 Views
Last Modified: 2012-08-13
I use this code to empty the recycle bin and it works in Windows 2000, XP, and 98, but in 98 there is a problem.
After the recycle bin gets emptied, the recycle bin icon on all the drives gets replaced by the folder "Recycled".
(not the desktop icon, just the recycle bin icon on the root drives, d:, e:, etc) BUT, if I run the app again right after emptying, the icons return.
I would like to have this fixed so that the recycle bin icons get refreshed after each time the recycle bin is emptied.  Also, I'm very much a beginner at this and I don't know if there is anything wrong with this code.
What I was trying to achieve was a command that would empty the recycle bin on all drives, silently, without confirmation, sound, etc. but I don't know if I did it right, even though it does seem to work, aside from the 98 problem.

This is how i have it now

Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long

Private Sub Command1_Click()
Const SHERB_NOCONFIRMATION = &H1
Const SHERB_NOPROGRESSUI = &H2
Const SHERB_NOSOUND = &H4

Dim retval As Long  ' return value
retval = SHEmptyRecycleBin(Form1.hwnd, "", SHERB_NOCONFIRMATION)
End Sub

TIA
jenny
0
Comment
Question by:jenny62
9 Comments
 
LVL 10

Expert Comment

by:aeklund
ID: 7178300
Try this.. remove the handle from the call..

retval = SHEmptyRecycleBin(0&, 0&, SHERB_NOCONFIRMATION)
0
 

Author Comment

by:jenny62
ID: 7178374
Doesn't empty the recycle bin at all with that line.
But thanks for your input.
jenny
0
 

Author Comment

by:jenny62
ID: 7178381
Doesn't empty the recycle bin at all with that line.
But thanks for your input.
jenny
0
 

Author Comment

by:jenny62
ID: 7178399
Doesn't empty the recycle bin at all with that line.
But thanks for your input.
jenny
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jenny62
ID: 7178426
Doesn't empty the recycle bin at all with that line.
But thanks for your input.
jenny
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7179601
TRy SHUpdateRecycleBinIcon API to update the Recycle Bin's Icon:

Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Long

Hope this help
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 75 total points
ID: 7179603
Example:

Const SHERB_NOCONFIRMATION = &H1
Const SHERB_NOPROGRESSUI = &H2
Const SHERB_NOSOUND = &H4
Private Type ULARGE_INTEGER
  LowPart As Long
  HighPart As Long
End Type
Private Type SHQUERYRBINFO
  cbSize As Long
  i64Size As ULARGE_INTEGER
  i64NumItems As ULARGE_INTEGER
End Type
Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Long
Private Declare Function SHQueryRecycleBin Lib "shell32.dll" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, pSHQueryRBInfo As SHQUERYRBINFO) As Long
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim RBinInfo As SHQUERYRBINFO, Msg As VbMsgBoxResult
    RBinInfo.cbSize = Len(RBinInfo)
    SHQueryRecycleBin vbNullString, RBinInfo
    If (RBinInfo.i64Size.LowPart And &H80000000) = &H80000000 Or RBinInfo.i64Size.HighPart > 0 Then
        Msg = MsgBox("Your Recycle Bin consumes over 2 gigabytes right now!" + vbCrLf + "Do you want to empty it?", vbYesNo + vbQuestion)
    Else
        Msg = MsgBox("Your Recycle Bin consumes" + Str$(RBinInfo.i64Size.LowPart) + " bytes right now." + vbCrLf + "Do you want to empty it?", vbYesNo + vbQuestion)
    End If
    If Msg = vbYes Then
        SHEmptyRecycleBin Me.hwnd, vbNullString, 0
        SHUpdateRecycleBinIcon
    End If
End Sub
0
 

Author Comment

by:jenny62
ID: 7180473
Well, maybe, but that code is not all silent, it asks for confirmation, and other stuff. I managed to get rid of some of the messages, but I don't know how to get rid of the main one that asks for confirmation.  I am very new at vb and this different code isn't clear to me.
How do I make this silent like the original?
No confirmation, no progress indicator, no sound, no message boxes at all.
Also, I pasted all the code into the general declarations of the Form.  Was that the right way to do it?
In my original, I had a module and a form.
Thanks for understanding.

jenny
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8040639
Hi jenny62,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept ryancys's comment(s) as an answer.

jenny62, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Input past end of file vbs script 9 81
VB error "Type mismatch" 2 49
A macro to Count the number of rows across all worksheets 3 80
Added a column screws up code 5 49
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now