简体   繁体   English

如何将文件复制到C:\\ Program Files(x86)\\

[英]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. 情况如下。

  1. Put the initial configuration file in the \\Cfg\\org.cfg 将初始配置文件放在\\ Cfg \\ org.cfg中

  2. When start application program,myApp.exe, check if configuration file exists in the application path. 启动应用程序myApp.exe时,请检查应用程序路径中是否存在配置文件。

  3. 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.

相关问题 C#如何使用Wiindows服务将文件复制到Program(x86)文件夹 - C# How to copy file into Program(x86) folder with Wiindows service 找不到文件'C:\\ Program Files(x86)\\ Common Files \\ Microsoft Shared \\ DevServer \\ 10.0' - Could not find file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0' System.IO.FileNotFoundException: '找不到文件'C:\Program Files (x86)\IIS Express\files'。 - System.IO.FileNotFoundException: 'Could not find file 'C:\Program Files (x86)\IIS Express\files'.' 从 PowerShell 运行位于 Program Files (x86) 中的文件 - Run a File, located in Program Files (x86) from PowerShell 加载配置文件时出错:访问路径 c:\\Program Files (x86)\\... 被拒绝 - Error occurred loading a configuration file: Access to path c:\Program Files (x86)\... denied 找不到文件“C:\\Program Files (x86)\\IIS Express\\GraceCancerFoundation.png” - Could not find file 'C:\Program Files (x86)\IIS Express\GraceCancerFoundation.png' 错误:“找不到文件'C:\\ Program Files(x86)\\ IIS Express \\ button.png'” - Error : `Could not find file 'C:\Program Files (x86)\IIS Express\button.png'` 错误在“C:\\\\ Program Files(x86)”中解压缩我的文件,没有权限 - Error unzip my file in “C:\\Program Files (x86)” , No permissions C# - 如何在 Windows 64 位上获取程序文件 (x86) - C# - How to get Program Files (x86) on Windows 64 bit 如何在程序文件(x86)安装文件夹winform应用程序中写入json文件? - How to write in a json file located into the Program files (x86) installation folder winform application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM