3

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?

2
  • 1
    You need to forget about ClickOnce. Commented Oct 29, 2011 at 14:18
  • You don't disable it, you simply don't use it to deploy your product. And use a regular installer, as created by a Setup and Deployment project. Not available in the Express edition. Commented Oct 29, 2011 at 15:39

1 Answer 1

2

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.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.