tags:

views:

1888

answers:

3

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.

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.

+2  A: 

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?

kokos
+2  A: 

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.

Keith
A: 

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.

Second, I'm not sure it's a good idea to delete other users' stuff but I guess you have a very good reason?

Coincoin