访问路径[我的路径]被拒绝 - 我需要帮助 [英] Access To Path [ My Path] Is Denied - I Need Help

查看:57
本文介绍了访问路径[我的路径]被拒绝 - 我需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助

i尝试了更多时间和不同的方法通过我的桌面应用程序通过C#复制文件.Net







Please i need help
i tried more of time and different ways to copy file through my Desktop Application by C#.Net



using (FileStream fs = new FileStream(SelectedFiles, FileMode.Open, FileAccess.Read))
                       {
                           FileIOPermission fp1 = new FileIOPermission(FileIOPermissionAccess.AllAccess, SelectedFiles);
                           FileIOPermission fp2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, StaticPath);

                           System.Security.AccessControl.FileSecurity SelectedFile = new System.Security.AccessControl.FileSecurity(SelectedFiles, System.Security.AccessControl.AccessControlSections.All);
                           System.IO.File.SetAttributes(SelectedFiles, FileAttributes.Normal);
                           System.IO.File.SetAccessControl(SelectedFiles, SelectedFile);
                           System.Security.AccessControl.FileSecurity MyPath = new System.Security.AccessControl.FileSecurity(StaticPath, System.Security.AccessControl.AccessControlSections.All);
                           System.IO.File.SetAttributes(StaticPath, FileAttributes.Normal);
                           System.IO.File.SetAccessControl(StaticPath, MyPath);

                          // System.IO.Path.Combine(SelectedFiles, StaticPath);
                           System.IO.File.Copy(StaticPath, SelectedFiles, true);
                       }

推荐答案

如果拒绝访问某些文件系统对象,则无法修复某些文件系统对象的访问权限通过此应用程序内的任何操作应用程序。试想一下:如果是UAC( http://en.wikipedia.org/wiki/User_Account_Control [ ^ ],彻底阅读它可以解决,为什么有人会创建和使用它?



您只能提升应用程序的权限运行您的应用程序以管理员身份,或使用您的权限提升来修改对文件系统对象的访问权限题。请参阅: http://www.sevenforums.com/tutorials/11841-run-administrator.html [ ^ ]。



或者,您可以创建一个嵌入应用程序清单,从一开始就自动强制提升: http://msdn.microsoft.com/en-us/library/bb756929.aspx [ ^ ]。



不,它不会绕过UAC对话框。 :-)



-SA
If access to some file system object is denied, you cannot fix its access by some application via any manipulations inside this application. Just think about it: if UAC (http://en.wikipedia.org/wiki/User_Account_Control[^], read about it thoroughly) could be worked around, why would anyone create and use it?

You can only elevate privilege for your application run your application "As Administrator", or use elevation of your privileges to modify the access to the file system object in question. Please see: http://www.sevenforums.com/tutorials/11841-run-administrator.html[^].

Alternatively, you can create an embed the application manifest, to force elevation automatically, from the very beginning: http://msdn.microsoft.com/en-us/library/bb756929.aspx[^].

No, it won't bypass the UAC dialog. :-)

—SA


这篇关于访问路径[我的路径]被拒绝 - 我需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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