public static void EmptyWastebasket(bool show_progress, bool play_sound, bool confirm) { RecycleFlags options = 0; if (!show_progress) { options = options | RecycleFlags.SHERB_NOPROGRESSUI; } if (!play_sound) { options = options | RecycleFlags.SHERB_NOSOUND; } if (!confirm) { options = options | RecycleFlags.SHERB_NOCONFIRMATION; } try { SHEmptyRecycleBin(IntPtr.Zero, null, (uint)options); } catch (Exception ex) { MessageBox.Show("Error emptying wastebasket.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void EmptyWastebasket(bool show_progress, bool play_sound, bool confirm) { RecycleFlags options = 0; if (!show_progress) { options = options | RecycleFlags.SHERB_NOPROGRESSUI; } if (!play_sound) { options = options | RecycleFlags.SHERB_NOSOUND; } if (!confirm) { options = options | RecycleFlags.SHERB_NOCONFIRMATION; } try { SHEmptyRecycleBin(IntPtr.Zero, null, (uint)options); } catch (Exception ex) { Trace.WriteLine("Error emptying wastebasket.\n" + ex.ToString()); } }
public static void EmptyRecycleBin() { RecycleFlags options = 0; options = RecycleFlags.SHERB_NOPROGRESSUI; options = RecycleFlags.SHERB_NOSOUND; options = RecycleFlags.SHERB_NOCONFIRMATION; try { SHEmptyRecycleBin(IntPtr.Zero, null, (uint)options); } catch (Exception ex) { MessageBox.Show("Error emptying wastebasket.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static extern uint SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);
public static extern int SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);
static int Main(string[] args) { bool confirm = false; bool progress = false; RecycleFlags flags = RecycleFlags.RecycleNoSound; string drive = null; // default: All drives string windrive = Path.GetPathRoot(Environment.SystemDirectory); #region Parse Command Line if (args.Length > 3) { return(ShowHelp( )); } foreach (string arg in args) { switch (arg.ToUpper( )) { case "/?": return(ShowHelp( )); case "/C": if (confirm) { return(ShowHelp("Duplicate command line switch /C")); } confirm = true; break; case "/P": if (progress) { return(ShowHelp("Duplicate command line switch /P")); } progress = true; break; case "/W": if (drive != null) { if (drive == windrive) { return(ShowHelp("Either specify a drive letter or use the /W switch, not both")); } else { return(ShowHelp("Duplicate drive specification {0} and {1}", drive, arg.ToUpper( ))); } } drive = windrive; break; default: bool validdrive = false; DriveInfo[] alldrives = DriveInfo.GetDrives( ); foreach (DriveInfo drvinf in alldrives) { if (drvinf.Name == arg.ToUpper( ) + "\\") { validdrive = true; drive = arg.ToUpper( ); } } if (!validdrive) { return(ShowHelp("Invalid command line argument \"{0}\"", arg)); } break; } } if (!confirm) { flags |= RecycleFlags.RecycleNoConfirmation; } if (!progress) { flags |= RecycleFlags.RecycleNoProgressUI; } #endregion Parse Command Line uint result = SHEmptyRecycleBin(IntPtr.Zero, drive, flags); if (result == 0) { return(0); } else { return(1); } }