我试图做一个自动备份程序,将文件夹复制到另一个文件夹中。很容易的任务:
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.
更多推荐
文件访问被拒绝更改权限
发布评论