Archive: Install as Admin, Run as User


Install as Admin, Run as User
I have NSIS/Unicode script that installs my application.
The installation requires admin privileges, which I get by setting up the privilege level
At the end of the installation, I want to launch my application.

My problem is that the application launches in Admin mode.
I'd like to launch it in user mode, just as if a user double clicked its icon.

Nothing I tried worked. Even setting down the level before launching wouldn't help.

What can I do?


I'd love to hear what you did when you tried "setting down the level" since such a thing is not possible.

The easy solution: Disable the run checkbox on the finish page
The hard solution: Use the UAC plugin


Anders,

I'd love to hear what you did when you tried "setting down the level" since such a thing is not possible.
There must be some way to reduce a process' privileges. This page http://msdn.microsoft.com/en-us/libr...px#elevationgl says "Once a task that requires administrative privileges is complete, the program should revert to the least privilege state." That phrase is used several times on the page.

I have not yet found where they tell how to revert to lower privileges.

Don

Is the reverse even true? I.e. can a process elevate itself mid-run? I was under the impression that it can't; that, at best, you can start a new process with the appropriate privileges.

There's some discussions out there on how to run an app as user from a higher elevation... one using the Task Scheduler ( http://www.codeproject.com/KB/vista-...aElevator.aspx ), one doing crazy things by getting the desktop (which it presumes to be non-elevated) and spawning a new process using that desktop's security tokens ( http://blogs.msdn.com/b/aaron_margos...vated-app.aspx <- http://blogs.microsoft.co.il/blogs/s...d-process.aspx ) and another that looks entirely like hieroglyphics after gazing at it for 2 minutes ( http://brandonlive.com/2008/04/27/ge...ou-part-2-how/ ).

But they're all about starting new processes - in which case, the UAC plugin should work quite well within the NSIS context and would be more flexible.


That's right, there are several hacky code samples out there that claim to "ride the elevator back down" but they are all hacks and will fail in certain configurations.