开发者

Delete files that windows does not want me to delete?

开发者 https://www.devze.com 2022-12-26 13:38 出处:网络
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

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?


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.)


It might not be a permissions issue, but a file locking issue. Both will appear to be a permissions issue.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消