文件访问被拒绝更改权限 [英] File access denied changing permissions

查看:358
本文介绍了文件访问被拒绝更改权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  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.

这篇关于文件访问被拒绝更改权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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