Edit environment variable in registry

余生颓废 提交于 2019-12-24 02:45:29

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/7939369/edit-environment-variable-in-registry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!