C#清空回收站

曾经用过bat处理回收站,但是效果很不理想(应该是我水平不够吧),后来发现C#可以直接调用系统dll,非常简单。下面是具体函数:  

class ClearRecycle
    {
        [DllImport("shell32.dll")]
        private static extern int SHEmptyRecycleBin(IntPtr handle, string root, int falgs);
        const int SHERB_NOCONFIRMATION = 0x000001;
        const int SHERB_NOPROGRESSUI = 0x000002;
        const int SHERB_NOSOUND = 0x000004;

        public static void Clear(System.Windows.Forms.Form form)
        {
            SHEmptyRecycleBin(form.Handle, "", SHERB_NOCONFIRMATION + SHERB_NOPROGRESSUI + SHERB_NOSOUND);
        }
    }

调用:

private void button1_Click(object sender, EventArgs e)
        {
            ClearRecycle.Clear(this);
        }

 

posted @ 2017-07-03 13:10  田云  阅读(630)  评论(0编辑  收藏  举报