具有管理权限的'System.UnauthorizedAccessException' [英] 'System.UnauthorizedAccessException' with administrative privileges

查看:94
本文介绍了具有管理权限的'System.UnauthorizedAccessException'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的程序,试图删除(通过File.Delete)ProgramData下目录中的文件。


即使我的帐户具有管理权限,我也会得到'System.UnauthorizedAccessException'和我的程序关闭而不删除文件。


有什么方法可以删除文件吗?


提前谢谢任何帮助。


- Michael Bate

解决方案

嗨MichaelBate,


感谢您发布此处


对于您的问题,您要删除的文件是什么?


通常,文件。 Delete()方法可以很好地工作,除了文件是特殊的。请尝试下面的代码。

 File.SetAttributes(filePath,FileAttributes.Normal); 
File.Delete( filePath );

最好的问候,


温迪


I wrote a simple program that attempts to delete (via File.Delete) a file in a directory underneath ProgramData.

Even though my account has administrative privileges I get the 'System.UnauthorizedAccessException' and my program closes without deleting the file.

Is there any way that I can delete the file?

Thanks in advance for any help.

- Michael Bate

解决方案

Hi MichaelBate,

Thank you for posting here

For your question, what is the file you want to delete?

Normally, File.Delete () method would work well except the file is special. Please try the code below.

File.SetAttributes(filePath, FileAttributes.Normal);
File.Delete(filePath);

Best Regards,

Wendy


这篇关于具有管理权限的'System.UnauthorizedAccessException'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆