Search code examples
c#uacelevated-privileges

Is it possible to elevate privileges of multiple child processes, prompting only once?


all. This may seem like a duplicate question, there being plenty of questions about elevating and de-elevating child processes on here.

I'm aware of the using UseShellExecute = true together with the Verb = "runas" option to start one's child process with elevated rights.

Example (found in many of the answers):

var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location)
{
    UseShellExecute = true, // !
    Verb = "runas", 
};

My problem here is not starting child processes with elevated access, I'd like to know if there is a way to prompt for elevated access only once, after which starting the same child process a few times, say 8 of them for example.

The application I'm working on uses a Queuing system to process tasks. According to the user's number of cores, a child process (QueueProcessor) is started for each of the cores, which then starts processing this queue. So in essence, I would like to check the user's rights, prompt once for elevated rights, and start all 8 Queue Processors.

I can't use the manifest-route to require the entire application to run in Admin-rights, as this is not an option for many of our users. EDIT as per @MPatel's comment: To clarify, we specifically don't force users to run the application as an Administrator as per design decisions.

And obviously you can see how it would become annoying when you'd have to click the UAC dialogue 8 times each time you'd want to run one of these tasks.

I came across this article: Vista UAC The Definitive Guide, during my searches, but I'm having trouble implementing the C++ dll in my C#, .NET 3.5 project. This is the article that basically lead me to ask whether this is possible.

One other thing which might be worth mentioning: I'm not sure if I'm misunderstanding the problem slightly. The users have to have at least enough access to use the basic SQL-funtionality our program uses. So I think my problem might be less about having the child process run with full admin-rights, as just getting the child process to start up. The issue I'm getting is that .NET won't allow certain users to run child processes from the running app. Having the user run the main app using "Run As Administrator" seems to fix this problem. Is there some UAC specific right I can possibly set once through a prompt to simply allow the main App to start the child.exe's?


Solution

  • You could write your own process (C# application) that will be started by your main application with elevated rights.

    Than, whenever you need to start a process with elevated rights you forward this request to your elevated process by using some kind of inter-process communication (NamedPipes, TcpClient, etc.) and that one will start this process as usual, leading to an elevated process cause it was started from an elevated one.