At my company, we are writing a script to take care of simple tasks that we usually would do by hand. I am using c# to delete profiles in c:\documents and settings\, except a few. These will simply be left alone. The problem is that even with code that sets the files to normal and marks the admin user as an owner, they won't delete. They say that the quick launch folder has access denied. I am using a recursive permissions change method and I know that it works. Same thing with file attributes. Why won't it work? How do I fix this?
It might not be a permissions issue, but a file locking issue. Both will appear to be a permissions issue.
It is very tricky, you will need to use PInvoke to call native APIs (and I'm not sure which ones). Unlocker, a utility to unlock files being used by other processes do this. It is not yet working with Windows 7 and 64-bit versions of some editions of windows.
The problem could be that other processes have open handles to those files or directories. To help you find out which processes are to blame, you could use the Find feature of Process Explorer to find them.
(Just to be clear: this isn't a suggestion on how you can write code to delete the files, but a suggestion on how to find out exactly what's preventing your current system from working.)
You can verify if this is being caused by file locking rather than access control by download the Process Explorer tool from http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
Run as Administrator and use the Find->Handle or Dll to see if it's being locked.
Otherwise you should be able to take ownership and grant access to delete without a problem.