在程序文件下运行.exe时出现System.UnauthorizedAccessException [英] System.UnauthorizedAccessException while running .exe under program files

查看:174
本文介绍了在程序文件下运行.exe时出现System.UnauthorizedAccessException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过WiX安装程序,我安装了Windows应用程序,并使用.exe和所需的dll在 c:\ProgramFiles 下创建了文件夹。

Through WiX installer I installed my Windows application and folder is being created under c:\ProgramFiles with .exe and required dll's.

运行.exe时,我收到 System.UnauthorizedAccessException

While running the .exe I am getting the System.UnauthorizedAccessException.

请让我知道是否有任何有用的建议。

Please let me know if there any helpful suggestions.

请找到以下事件日志以供参考。

Please find the below event log for reference.

Application: xxxxxxx.exe
Framework Version: v1.0.0
Description: The process was terminated due to an unhandled exception.
Exception Info: System.UnauthorizedAccessException
   at System.IO.__Error.WinIOError(Int32, System.String)
   at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
   at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean)
   at System.IO.StreamWriter.CreateFile(System.String, Boolean, Boolean)
   at System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding, Int32, Boolean)
   at System.IO.StreamWriter..ctor(System.String, Boolean)
   at System.IO.File.AppendText(System.String)


推荐答案

不要尝试在应用程序不应写的地方写东西。使用其他文件夹,例如:

Don't try to write where applications should not write. Use other folders like for example:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

如果没有其他选择,我非常怀疑,请以管理权限运行可执行文件。

If there is no possible alternative, which I seriously doubt, run the executable with administrative privileges.

https://msdn.microsoft.com/en-us/ library / bb756929.aspx

这篇关于在程序文件下运行.exe时出现System.UnauthorizedAccessException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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