Pregunta

I'm working on a project which requires Administrator rights after clicking a button. currently using C# and VB.NET. Your answer language is up to you, but better if it is in one of them. :)

I already tried the following:

  • "runas" verb with a new process but the problem is that it re-starts the application which means losing all current progress and variable values.
  • editing manifest file, but I "don't want to force" the user to run the application as admin.

As previously said, Administrator Right required only when clicking on a button. If it never been clicked then No rights needed!

So, is there anyway to grant Administrator rights during run-time via UAC, for instance. Without restarting the application.

I've searched the web and all I got was the methods already mentioned above :)

NOTE: I found something similar to what I need in Microsoft Security Essential where it's able to grant Administrator rights without starting a new instance of the application.

MSE can do it! Description: When running MSE, by default, you'll find in History tab that first radio box is chosen. changing this to any other option and granting the right won't restart application therefore, maintaining current state.

Any help is very appreciated.

¿Fue útil?

Solución

There is no way to elevate during the lifetime of a process. Whether or not your process runs elevated is decided at process startup time.

I found something similar to what I need in Microsoft Security Essential where it's able to grant Administrator rights without starting a new instance of the application.

No, MSE will be performing the elevated tasks in a separate process.

You don't need to close the existing process and start a new one. What you are expected to do is to use a separate process to perform just the tasks that require elevation. That separate process does not need to show any UI. The elevated process can remain hidden and communicate with the process that displays the UI. The cleanest way to achieve this is to put the elevated tasks inside an out-of-process COM server and to use CoCreateInstanceAsAdmin.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top