如何从 c# 中的 Windows 服务应用程序清空所有用户的回收站
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I empty the recycle bin for all users from a Windows service application in c#
提问by Dean Bates
I'm looking for a c# snippet which I can insert in a Windows service. The code must empty the recycle bin for all users on the computer.
我正在寻找可以插入到 Windows 服务中的 ac# 片段。该代码必须清空计算机上所有用户的回收站。
I have previously tried using SHEmptyRecycleBin
(ref http://www.codeproject.com/KB/cs/Empty_Recycle_Bin.aspx) however the code doesn't work when ran from a windows service as the service is running with local system privileges.
我以前曾尝试使用SHEmptyRecycleBin
(参考http://www.codeproject.com/KB/cs/Empty_Recycle_Bin.aspx)但是当从 Windows 服务运行时代码不起作用,因为该服务以本地系统权限运行。
回答by kokos
I think doing something like this is against Microsoft recommended practices. What are you trying to do that requires emptying the Recycle Bin from a Windows service?
我认为做这样的事情违反了微软推荐的做法。你想做什么需要从 Windows 服务清空回收站?
回答by Keith
Hopefully you can't.
希望你不能。
A service running as the local machine should not be clearing my Recycle bin, ever.
作为本地机器运行的服务永远不应该清除我的回收站。
You could promote the service to run as an Admin account then it would have the right (and be a security risk), but why do you want to do this? It sounds like the sort of think Viruses try to do.
您可以将服务提升为作为管理员帐户运行,然后它就有权利(并且存在安全风险),但是您为什么要这样做呢?这听起来像是病毒试图做的那种想法。
回答by Coincoin
First, have you tried running the service on an interactive user account? Maybe SHEmptyRecycleBin requires an interactive user even though it doesn't necessarily display a Window.
首先,您是否尝试过在交互式用户帐户上运行该服务?也许 SHEmptyRecycleBin 需要一个交互式用户,即使它不一定显示一个窗口。
Second, I'm not sure it's a good idea to delete other users' stuff but I guess you have a very good reason?
其次,我不确定删除其他用户的内容是否是个好主意,但我想你有一个很好的理由?