Mauro Ganswer
Mauro Ganswer

Reputation: 1419

Elevating privileges programmatically and as more user friendly as possible

As far as I understood it is not possible to rise privileges within the running process. Hence - as suggested here - from my MainApp (deployed through ClickOnce) I'm currently launching a separate Process (a signed exe let's call it Foo.exe) used to run activities requiring admin privileges:

Process p = new Process();
p.StartInfo.FileName = "Foo.exe";
p.StartInfo.Arguments = "args...";
p.StartInfo.UseShellExecute = true;
p.StartInfo.Verb= "runas";
p.Start();
p.WaitForExit();

Now I would like to make this procedure as friendly as possible for the user. I've two main concerns.

  1. The user is prompted with the UAC window showing:

    Program Name: Foo
    Publisher: OurCompany
    File Origin: Hard drive on this computer
    Program Location: %path% + %arguments%

    I need to hide the arguments (there is some sensible information not so crucial but showing it so easily is not good) and possibly I would like also to change the Program Name to MainApp so that the user recognize the app name he is used to.

  2. I would like to make the main form in Foo the child of the main form in MainApp so that for instance I can easily display the main form in Foo in the center of its parent

Upvotes: 2

Views: 651

Answers (1)

Sam Axe
Sam Axe

Reputation: 33738

I would suggest launching a second copy of your application with the elevated privleges.. then use SendMessage and WM_COPYDATA (or some user-defined offset above WM_USER) to post a message/s to the new instance instructing it what to do (pass those args, tell it where to center itsself, etc). Or use some other form of IPC (inter-process communication: windows messages, named piped, memory mapped files, tcp/ip, etc...)

In this manner you can retain the application name, the signature, the program location.. everything looks normal to the user.

You may go so far as to launch the form from the un-elevated process and only handle data processing on the elevated side - passing data via your coice of IPC.

Upvotes: 2

Related Questions