Search

Empty the Recycle Bin

This C# code snippet empties the Recycle Bin. Windows will display a confirmation dialog box.
using System.Runtime.InteropServices;
...
 
enum RecycleFlags : uint
{
   SHERB_NOCONFIRMATION = 0x00000001,
   SHERB_NOPROGRESSUI   = 0x00000002,
   SHERB_NOSOUND        = 0x00000004
}
 
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
static extern uint SHEmptyRecycleBin 
 (IntPtr hwnd, 
 string pszRootPath,
 RecycleFlags dwFlags);
 
public static void Main()
{
    uint result = SHEmptyRecycleBin (IntPtr.Zero, null, 0);
    Console.WriteLine ("Result: {0}", result);
}