Exemplo n.º 1
0
        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());
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 static extern uint SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath,
 RecycleFlags dwFlags);
Exemplo n.º 5
0
 public static extern int SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);
Exemplo n.º 6
0
        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);
            }
        }