我想要一个可以在Windows7|8中直接在“回收站”中打开explorer.exe的WPF按钮。这是因为我的应用程序擦除了很多文件,我想为用户提供一种快速恢复文件的方法。命令行参数不起作用,可能是因为“回收站”是一个虚拟目录。我试过使用"$Recycle Bin“。Explorer.exe /root出现故障,其中a是虚拟文件。尝试保护回收站中的空间似乎不起作用。
这是Scott Powell的工作代码,我测试过并正在使用。谢谢你,Scott@
private void ExploreTrashBin ( )
{
String str_RecycleBinDir = String.Format(@"C:\$Recycle.Bin\{0}", UserPrincipal.Current.Sid);
Process . Start ( "explorer.exe" , str_RecycleBinDir );
}
private void TrashBin_Button_Click ( object sender , RoutedEventArgs e )
{
ExploreTrashBin ( );
}发布于 2015-02-04 09:26:51
您可以执行以下命令来实现这一点,
start shell:RecycleBinFolder从您可以使用的C#代码中,
System.Diagnostics.Process.Start("explorer.exe", "shell:RecycleBinFolder");发布于 2015-02-04 09:31:54
回收站位于名为\$Recycle.Bin\%SID%的隐藏目录中,其中%SID%是执行删除的用户的SID。
因此,基于此,我们可以执行以下操作:向System.DirectoryServices.AccountManagement添加一个.NET引用
string str_RecycleBinDir = UserPrincipal.Current.Sid;
Process.Start("explorer.exe","C:\$Recycle.Bin\" + str_RecycleBinDir);现在应该能够根据正在运行的用户帐户访问正确的回收站目录。在Windows 7中工作(已测试)。
https://stackoverflow.com/questions/28311915
复制相似问题