简体   繁体   中英

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. This works fine from Visual Studio 2010. When running from the .EXE file, I get a System.UnauthorizedAccessException when writing the file.

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.

Perhaps you want to re-evaluate storing that data (XML) in that location all the time. 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).

The question below seems to outline a work-around depending on the user's priv level.

writing files to Common Application Data folder denied

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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