编辑注册表中的环境变量 [英] Edit environment variable in registry
问题描述
因此,我读到本地的子项机器:
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。这是一个设计选择。您的选项是:
- 使用标准的安装包,可以显示UAC标高对话框。
- 修改用户的
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:
- Use a standard install package which will allow you to show the UAC elevation dialog.
- 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屋!