如何写入程序文件(x86)文件夹? [英] How can I write to program files(x86) folder?

查看:102
本文介绍了如何写入程序文件(x86)文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在Visual Studio 2013中使用C#。我在使用安装程序时遇到问题,所以我自己写了。它运行良好,除了因为我收到UnauthorizedAccessException错误而无法写入Program Files目录。是否有解决方法?

Hello,

I am working with C# in Visual Studio 2013. I am having issues with using a setup program so I have written my own. It works well except for the fact that I can not write to the Program Files directories as I get an UnauthorizedAccessException error. Is there a work around with this?

推荐答案

您无法写入Programs Files文件夹(或其任何子文件夹或Program Files) (x86)出于安全原因没有管理员权限 - 任何在那里写入的尝试都很可能是病毒活动!



您可以这样做 - 您只需提升您的应用程序:使用C#获得高级权限提升 [ ^ ]应该有所帮助请注意,这将打开UAC对话框,用户必须确认他的权限 - 没有办法解决这个问题!
You can't write to the "Programs Files" folder (or any of it's sub-folders, or "Program Files (x86)" without Admin permissions for security reasons - any attempt to write there is quite possibly virus activity!

You can do it - you just have to elevate your application: Getting Elevated Privileges on Demand using C#[^] should help. Do note that this will bring up the UAC dialog and the user must confirm his permission - there is no way round that!


标准做法是不允许用户应用程序写入程序文件文件夹。



而是应用程序的本地文件数据d写入本地或漫游APPDATA文件夹或TEMP文件夹中的文件夹。请参阅 http://msdn.microsoft.com/EN- US / library / windows / desktop / ms723686(v = vs.85).aspx [ ^ ]
The standard practice is to not allow user applications to write to the Program Files folders.

Instead, local file data for an application should be written to a folder in either a local or roaming APPDATA folder or in the TEMP folder. SEE http://msdn.microsoft.com/EN-US/library/windows/desktop/ms723686(v=vs.85).aspx[^]


支持解决方案2:更一般地说,取决于什么你需要,你通常应该使用其中一个特殊文件夹。



请在我过去的答案中查看更多细节:如何找到我的程序目录 [ ^ ]。



-SA
In support of Solution 2: more generally, depending on what you need, you usually should use one of the "special folders".

Please see further detail in my past answer: How to find my programs directory[^].

—SA


这篇关于如何写入程序文件(x86)文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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