+92 332 4229 857 99ProjectIdeas@Gmail.com

How to empty recycle bin (Vb.net)


Empty recycle bin(Vb.net)
To empty recycle bin, there are two functions:
SHEmptyRecycleBin
SHUpdateRecycleBinIcon
which are provided in Windows by library "shell32.dll".
SHEmptyRecycleBin deletes all the items in the recycle bin, where as SHUpdateRecycleBinIcon updates the icon of the recycle bin after it is empted.



How to use the code
First add a new form and name it as Frm_EmptyRecycleBin,
Second add a button and name it as btn_EmptyRecycleBin,
After doing this just paste the code given below in the code section(.vb) of this form.


CODE
Public Class Frm_EmptyRecycleBin

#Region "Libraries"
    Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" _
    Alias "SHEmptyRecycleBinA" (ByVal hWnd As Int32, ByVal pszRootPath As String, _
    ByVal dwFlags As Int32) As Int32
    Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Int32
#End Region

#Region "Declarations"
    Private Const SHERB_NOCONFIRMATION = &H1
    Private Const SHERB_NOSOUND = &H4
#End Region

    Private Sub emptyRecycleBin()
        SHEmptyRecycleBin(Me.Handle.ToInt32, vbNullString, _
        SHERB_NOCONFIRMATION + SHERB_NOSOUND)
        SHUpdateRecycleBinIcon()
    End Sub

    Private Sub btn_EmptyRecycleBin_Click _
    (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_EmptyRecycleBin.Click
        Try
            emptyRecycleBin()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

End Class

0 comments: