编辑注册表中的环境变量 [英] Edit environment variable in registry

查看:201
本文介绍了编辑注册表中的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从注册表中读取所有环境变量,并在visual studio 2010 express中使用c#设置一个新值。



因此,我读到本地的子项机器:

  SYSTEM\CurrentControlSet\Control\Session Manager\Environment 

,其值为 Path

阅读路径值:

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

我收到一个例外,我没有这个权限。



因此,我在清单中设置值:

 < requestedExecutionLevel level =requireAdministrator uiAccess =false/> 

但是现在我无法编译我的项目,因为ClickOnce不支持它。
如何编译​​具有requireAdministrator的安全级别的项目?
我发现一个解决方案是在没有requireAdministrator级别的情况下进行编译,之后我更改了myproject.exe.manifest中的值。我看到对了,我总是必须将这两个文件(manifest& exe-file)复制到另一台计算机才能正确运行?可以通过编译将信息放在exe文件中?

解决方案

如果要在安装过程中提升,那么可以不要使用ClickOnce。这是一个设计选择。您的选项是:


  1. 使用标准的安装包,可以显示UAC标高对话框。

  2. 修改用户的 PATH 环境而不是系统范围的变量。此选项与ClickOnce的每用户理念完全兼容。


I want to read all environment variable from the registry and set a new value for it with c# in visual studio 2010 express.

Thus I read the subkey of local machine:

SYSTEM\CurrentControlSet\Control\Session Manager\Environment

and there the value of Path.
While reading the Path value:

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. How can I compile a project with security level of requireAdministrator? One solution I found is to compile it without the requireAdministrator level and afterwards I changed the value in 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? Is it possible to put the information in the exe-file by compiling?

解决方案

If you want to elevate during installation then you can't use 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.
  2. Modify the user's PATH environment rather than the system-wide variable. This option is perfectly compatible with the per-user philosophy of ClickOnce.

这篇关于编辑注册表中的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆