具有管理权限的'System.UnauthorizedAccessException'

编程入门 行业动态 更新时间:2024-10-27 02:18:18
本文介绍了具有管理权限的'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'

本文发布于:2023-11-11 06:46:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577663.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理权限   UnauthorizedAccessException   System

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!