在程序文件下运行 .exe 时出现 System.UnauthorizedAccessException [英] System.UnauthorizedAccessException while running .exe under program files
问题描述
通过 WiX 安装程序,我安装了我的 Windows 应用程序,并在 c:ProgramFiles
下创建了带有 .exe 和所需 dll 的文件夹.
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屋!