C# 如何以编程方式清除Windows下的回收站?
如果我想通过编程清除Windows下的回收站,如何实现C# 如何以编程方式清除Windows下的回收站?,c#,.net,c,windows,winapi,C#,.net,C,Windows,Winapi,如果我想通过编程清除Windows下的回收站,如何实现 IFileOperation是否有帮助?您可以使用shell32.dll库中的SHEmptyRecycleBin()函数来实现此目的。完整示例: using System; using System.Runtime.InteropServices; class Program { enum RecycleFlags : uint { SHERB_NOCONFIRMATION = 0x00000001,
IFileOperation
是否有帮助?您可以使用shell32.dll
库中的SHEmptyRecycleBin()
函数来实现此目的。完整示例:
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
}
}
}
@Sughakar当你的答案包含一个相同问题的链接时,最好以重复的方式投票结束。如果你不能投票,就留下一条评论,大意是这个问题是重复的。@DavidHeffernan:好的,大卫,谢谢你的意见。我会跟进的。