2

在我的公司,我们正在编写一个脚本来处理我们通常手动完成的简单任务。我正在使用 c# 删除 c:\documents and settings\ 中的配置文件,少数除外。这些将被单独留下。问题是,即使使用将文件设置为正常并将管理员用户标记为所有者的代码,它们也不会删除。他们说快速启动文件夹的访问被拒绝。我正在使用递归权限更改方法,我知道它有效。与文件属性相同。为什么它不起作用?我该如何解决?

4

4 回答 4

6

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

于 2010-04-13T20:41:52.547 回答
3

这可能不是权限问题,而是文件锁定问题。两者似乎都是权限问题。

于 2010-04-13T20:33:27.087 回答
1

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.

于 2010-04-13T20:43:10.817 回答
0

这非常棘手,您将需要使用 PInvoke 来调用本机 API(我不确定是哪些)。Unlocker是一个用于解锁其他进程正在使用的文件的实用程序。它尚不适用于 Windows 7 和某些 Windows 版本的 64 位版本。

于 2010-04-13T20:37:01.673 回答