[英]How to copy file to the C:\Program Files (x86)\
I can copy files to the C:\\Program Files (x86)\\...
...but only with the administrator account. 我可以将文件复制到
C:\\Program Files (x86)\\...
,但只能使用管理员帐户。
This file is a configuration file like App.Config
, but with a different name, and I want to put it into the application path's sub folder. 该文件是一个类似于
App.Config
的配置文件,但是名称不同,我想将其放入应用程序路径的子文件夹中。
The scenario is like following. 情况如下。
Put the initial configuration file in the \\Cfg\\org.cfg 将初始配置文件放在\\ Cfg \\ org.cfg中
When start application program,myApp.exe, check if configuration file exists in the application path. 启动应用程序myApp.exe时,请检查应用程序路径中是否存在配置文件。
If it doesn't exist, copy org.cfg to the myApp.exe.config and load it. 如果不存在,请将org.cfg复制到myApp.exe.config并加载它。
I tried DirectoryInfo.SetAccessControl() but following error occur as well. 我尝试使用DirectoryInfo.SetAccessControl(),但也会发生以下错误。
"Attempted to perform an unauthorized operation" “试图执行未经授权的操作”
Program Files (x86)
required administrative permission to write to. Program Files (x86)
需要写入的管理权限。 So does changing the permissions, which is why SetAccessControl
fails. 更改权限也是如此,这就是
SetAccessControl
失败的原因。 There's really no way around that. 真的没有办法解决。 If you want to have your configuration file writable by the application, then you might consider changing the permission of the configuration file during installation of the program when you do have administrative access.
如果希望配置文件可被应用程序写入,那么当您具有管理访问权限时,可以考虑在程序安装期间更改配置文件的权限。
I would instead however recommend putting your configuration file somewhere in the user's profile, which is writable by default for all users, like in %LOCALAPPDATA%
. 但是,我建议您将配置文件放置在用户配置文件中的某个位置,默认情况下,该配置文件对所有用户都是可写的,例如
%LOCALAPPDATA%
。
You can load configuration files from arbitrary locations as well, it doesn't have to be in the .config
file next to the executable. 您也可以从任意位置加载配置文件,它不必位于可执行文件旁边的
.config
文件中。 For an example of that, look at this question . 例如,请看这个问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.