简体   繁体   English

.exe的未经授权的访问异常写入文件

[英]Unauthorized Access Exception writing file from .exe

My WPF application writes an XML file to a folder within the CommonApplicationData folder on a Windows 7/64 machine. 我的WPF应用程序将XML文件写入Windows 7/64计算机上的CommonApplicationData文件夹内的文件夹中。 This works fine from Visual Studio 2010. When running from the .EXE file, I get a System.UnauthorizedAccessException when writing the file. 从Visual Studio 2010可以正常工作。从.EXE文件运行时,写入文件时出现System.UnauthorizedAccessException。

Is this a problem with my initial setup of the folder? 我的文件夹初始设置是否有问题? Or is this related to the permissions of the executable file itself? 还是这与可执行文件本身的权限有关? Not quite sure how to handle this one?? 不太确定该如何处理?

Paul 保罗

I think that it is a problem with permissions to the folder. 我认为该文件夹的权限存在问题。 Probably Visual Studio runs your application as an administrator and the .EXE file is executed as a normal user. 可能Visual Studio以管理员身份运行您的应用程序,而.EXE文件是以普通用户身份执行的。

Perhaps you want to re-evaluate storing that data (XML) in that location all the time. 也许您想一直重新评估将数据(XML)始终存储在该位置。 Limited users won't be able to write to it. 受限用户将无法对其进行写入。 Sure, you can force admin privs but your users may not always have that option (and it's kinda a hack anyway). 当然,您可以强制执行admin privs,但您的用户可能并不总是拥有该选项(无论如何,这还是一种hack)。

The question below seems to outline a work-around depending on the user's priv level. 下面的问题似乎概述了一种变通方法,具体取决于用户的priv级别。

writing files to Common Application Data folder denied 将文件写入Common Application Data文件夹被拒绝

右键单击* .exe文件,然后单击“以管理员身份运行”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM