stormsam
stormsam

Reputation: 189

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.

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?

Upvotes: 3

Views: 1659

Answers (1)

David Heffernan
David Heffernan

Reputation: 613342

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.

Upvotes: 2

Related Questions