Question

I've got a piece of code that calls the DeleteFile method in the Microsoft.VisualBasic.FileIO.FileSystem class (in the Microsoft.VisualBasic assembly) in order to send the file to the Recycle Bin instead of permanently deleting it. This code is in a managed Windows Service and runs on a Win Server 2k8 machine (32-bit).

The relevant line:

FileSystem.DeleteFile(file.FullName, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin, UICancelOption.DoNothing);

Of course, I've got "using Microsoft.VisualBasic.FileIO;" at the top of the class and I verified that the method being called is really on the FileSystem class in that namespace. In the above line I refer to a local variable "file" - that's a FileInfo for a local file (say, C:\path\to\file.txt) of which I'm certain that it exists. The application has Full Control over both the file and the directory it's in.

This appears to work just fine as the file disappears from the directory it was in. However, the file doesn't show up in the Recycle Bin. I tried inspecting the C:\$Recycle.Bin folders manually as I suspected the Windows Service running in session 0 would make it end up in a different Recycle Bin, but all the Recycle Bins appear empty.

Does anybody have a clue as to what causes this behavior?

By the way - the machine is definitely not out of free space on the drive in question (or any other drive for that matter), and the file is very small (a couple of kilobytes, so it doesn't exceed the Recycle Bin threshold).

Was it helpful?

Solution

I assume your service is running under a different user account than your own (or one of the special service accounts).

I don't believe it's possible for one user to view the contents of another user's recycle bin - even though you can see some evidence of their existence within the C:\$Recycle.Bin folder.


If it's running under another user account, try logging into the machine using that account, and then check the recycle bin. If it's running under a service account (e.g. Local Service, Network Service, or Local System) it's going to be trickier.

Given that the recycle bins are separate, how are you planning to make use of the fact that the file is in the recycle bin anyway?

OTHER TIPS

the problem could come from the user executing your service, could you try to alter the executing user policy or change the executing user.

Anyway, it could also come from the service being executed without a shell, as the recycle bin depend on the shell api. this post seem to confirm this issue. So you would need to take another approach to acces shell api from your service.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top