【问题标题】:How to programatically clear the recycle bin under Windows?如何以编程方式清除 Windows 下的回收站?
【发布时间】:2013-11-14 04:12:19
【问题描述】:

如果我想以编程方式清除 Windows 下的回收站,如何实现?

IFileOperation 有帮助吗?

【问题讨论】:

    标签: c# .net c windows winapi


    【解决方案1】:

    您可以使用shell32.dll 库中的SHEmptyRecycleBin() 函数来实现此目的。

    【讨论】:

    • @Sughakar 当您的答案包含指向相同问题的链接时,最好投票以重复关闭。如果您无法投票,请发表评论,表明该问题是重复的。
    • @DavidHeffernan : 当然,大卫,感谢您的意见。我会跟进的。
    【解决方案2】:

    完整示例:

    using System;
    using System.Runtime.InteropServices;
    
    class Program
    {
        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);
    
        static void Main(string[] args)
        {
            uint result = SHEmptyRecycleBin(IntPtr.Zero, null, 0);
            if (result == 0)
            {
                //OK
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-05-17
      • 1970-01-01
      • 2023-03-12
      • 2022-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多