c# - 在程序文件下运行 .exe 时出现 System.UnauthorizedAccessEx

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

在运行 .exe 时,我得到了 System.UnauthorizedAccessException

如果有任何有用的建议,请告诉我。

请查找以下事件日志以供引用。

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)

最佳答案

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

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

如果没有其他可能的选择(我对此深表怀疑),请以管理权限运行可执行文件。

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

关于c# - 在程序文件下运行 .exe 时出现 System.UnauthorizedAccessException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50587622/

相关文章:

python-3.x - 如何在不更改 css 的情况下共享 pytest-html 的 html

python - 如何将 Pyspark Dataframe header 设置为另一行?

qt - 没有安装 qmlscene : why is a warning sign next to

python - 如何使用具有 NaN 值的 Pandas 计算中位数?

python - 遍历列表,比较值并删除重复项 - Python

css - 如何突出显示 ionic 列表中的选定元素

xamarin - 类型 'StackLayout' 的值不能添加到类型 'IList' 的集合或字

javascript - 如何从url获取json数据并保存到const变量【TypeScript】

powershell - 在 PowerShell 中比较字符串中的日期

r - 重新启动的组计数器(使用 R data.table)