简体   繁体   English

如何从c#中的Windows服务应用程序中为所有用户清空回收站

[英]How can I empty the recycle bin for all users from a Windows service application in c#

I'm looking for ac# snippet which I can insert in a Windows service. 我正在寻找可以在Windows服务中插入的ac#代码段。 The code must empty the recycle bin for all users on the computer. 该代码必须为计算机上的所有用户清空回收站。

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 SHEmptyRecycleBin http://www.codeproject.com/KB/cs/Empty_Recycle_Bin.aspx ),但是当从Windows服务运行时该代码不起作用,因为该服务正在以本地系统特权运行。

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. 听起来像是病毒尝试做的那种思考。

I think doing something like this is against Microsoft recommended practices. 我认为这样做是违反Microsoft建议做法的。 What are you trying to do that requires emptying the Recycle Bin from a Windows service? 您要做什么,需要从Windows服务中清空回收站?

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不需要交互式用户,即使它不一定显示Window。

Second, I'm not sure it's a good idea to delete other users' stuff but I guess you have a very good reason? 其次,我不确定删除其他用户的资料是个好主意,但我想您有很好的理由吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM