文件访问被拒绝更改权限

编程入门 行业动态 更新时间:2024-10-28 20:27:42
本文介绍了文件访问被拒绝更改权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图做一个自动备份程序,将文件夹复制到另一个文件夹中。很容易的任务:

File.Copy(Source,Destination);

来源类似于 C:\Users\SomeUser\MyDocuments \ SavedFiles 目的地类似于 D:\ BackUp

但是当我运行我的程序时,出现访问路径 C:\blabla ..... 访问被拒绝的错误。

是否有任何类型的权限必须改为使用 Copy 方法?我想是这样的。有什么想法吗? 更新 p>

$ b $您必须假定您可能没有权限访问硬盘上的某些文件和文件夹。

一个解决方案是使用管理员级权限手动运行您的应用程序,但修改清单文件比较容易应用程序在运行时自动查找管理员级别。

您可以通过将mainifest文件添加到您的项目(添加新项目...)。

然后换行

< requestedExecutionLevel level =asInvokeruiAccess =false/>

< requestedExecutionLevel level =requireAdministratoruiAccess =false/>

显然,如果要运行该程序的用户没有一个管理员级别的帐户。

I'm trying to do an auto-backup program that takes a folder and copies it into another folder. Pretty easy task :

File.Copy(Source, Destination);

Source is something like C:\Users\SomeUser\MyDocuments\SavedFiles Destination is something like D:\BackUp

But when I run my program , I get "Error with access to the path C:\blabla..... access is denied.

Is there any type of permission I must change to use the Copy method ? I guess so.. I looked a little but I can't find where to change such a thing. Any Idea ?

UPDATE

解决方案

You have to assume that you might not have permission to access some files and folders on your hard drive.

One solution is to manually run your application with administrator-level permissions, but it is easier to modify the manifest file so that the application automatically seeks admin level when it is run.

You can do this by adding a mainifest file to your project (Add new item...).

Then change the line

<requestedExecutionLevel level="asInvoker" uiAccess="false" />"

to

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />"

Obviously, this might not solve your problem if the user who is meant to run the program does not have an administrator-level account.

更多推荐

文件访问被拒绝更改权限

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

发布评论

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

>www.elefans.com

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