简体   繁体   English

在注册表中编辑环境变量

[英]Edit environment variable in registry

I want to read all environment variable from the registry and set a new value for it with c# in visual studio 2010 express. 我想从注册表中读取所有环境变量,并在Visual Studio 2010 Express中使用C#为它设置一个新值。

Thus I read the subkey of local machine: 因此,我读取了本地计算机的子项:

SYSTEM\CurrentControlSet\Control\Session Manager\Environment

and there the value of Path . 还有Path的值。
While reading the Path value: 在读取Path值时:

reg = Registry.LocalMachine.OpenSubKey(SUB_KEY_PATH, true);

I get an exception, that i don't have the permission for it. 我得到一个例外,我没有许可。

Therefore I set the value in the manifest: 因此,我在清单中设置了值:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

But now I can't compile my project, because ClickOnce doesn't support it. 但是现在我无法编译我的项目,因为ClickOnce不支持它。 How can I compile a project with security level of requireAdministrator? 如何编译安全级别为requireAdministrator的项目? One solution I found is to compile it without the requireAdministrator level and afterwards I changed the value in myproject.exe.manifest. 我发现的一种解决方案是在没有requireAdministrator级别的情况下进行编译,然后更改myproject.exe.manifest中的值。 Did i see it right, that I always have to copy both files (manifest & exe-file) to another computer to run it correctly? 我是否正确,我总是必须将两个文件(清单和exe文件)都复制到另一台计算机上才能正确运行? Is it possible to put the information in the exe-file by compiling? 是否可以通过编译将信息放入exe文件?

If you want to elevate during installation then you can't use ClickOnce. 如果要在安装过程中提升高度,则不能使用ClickOnce。 That's a design choice. 那是设计选择。 Your options therefore are: 因此,您的选择是:

  1. Use a standard install package which will allow you to show the UAC elevation dialog. 使用标准安装软件包,该软件包将允许您显示UAC高程对话框。
  2. Modify the user's PATH environment rather than the system-wide variable. 修改用户的PATH环境,而不是系统范围的变量。 This option is perfectly compatible with the per-user philosophy of ClickOnce. 此选项与ClickOnce的每用户哲学完全兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM