Archive: Using UAC.dll based on folder selected and OS


Using UAC.dll based on folder selected and OS
I have an installer which needs to prompt for Admin User Name and Password only in case the OS(Vista/Win7...etc) requires this for Program Files. If the user changes the install location to some other folder, then this prompt should not come up.

What I am trying to say is I need to elevate the user level only in case the selected folder is Program Files and only if the OS needs it.

I have gone through the NSIS Wiki, and this forum :confused:but am not able to find a working solution.

I always end up getting -> Unable to elevate, error .

I would really appreciate if someone has a working example, or some ideas on how to achieve this, as this is really blocking my work.


What you are requesting does not make sense:

1) 2000/XP/2003 should also prompt for username/pwd since you can't write to ProgramFiles as a standard user

2) Where would you store uninstall info? HKLM or HKCU, just based on installdir?


Actually what he's requesting does make sense. If you recall, that's exactly what I did using your plugin. And as I recall, you correctly noted that that is not what the plugin is designed for. :)

divyaa, what you want to do is not easy at all, because you'll run into a lot of issues that are not trivial to overcome. Here's what I ended up doing:
1) Call for elevation only when the user does something that will require admin.
2) Upon elevation, make the inner instance synchronize all important variables and component states. Then jump to the page that the user elevated from.
3) Be careful not to mix up userlevel (HKCU) and adminlevel (HKLM) installs! It's one of the two, never both. Probably the only case where you may mix them is if you need admin to grant alluser access on a directory, but still want a userlevel install.

Things to take into account:
- To test if a directory is writable, use: http://forums.winamp.com/showthread.php?t=317018
- I had trouble hiding the outer instance after elevation from an installer page. Solution: http://nsis.pastebin.com/hY8zmviQ
- Page skipping into a conditional page (custom page code with an ${If} clause) is a disaster. Solution: http://forums.winamp.com/showthread.php?t=316154
- Mixed mode installation is easy, using the UAC plugin. Mixed mode UNinstallation is more difficult, because when uninstall is run from ARP it will automatically elevate, no matter what executionlevel is requested. Solution: http://forums.winamp.com/showthread.php?t=277801

Kudos to the guru: Most of these tricks are inspired by Anders. :)


No it does not make sense, changing from single user to all user install just based on the destination directory is crazy! But yeah, I never said it was not possible.


Heh, I suppose that much is true. But using a fully mixedmode installer I can still do userlevel singleuser installation even after elevation. You just have to jump through a lot more hoops to get the installation script working properly. (Basically the installer ends up circumventing folder protection, while otherwise staying userlevel.)

And on the other hand, the 'elevate only for admin tasks' concept is very user-friendly, and I'm happy that more and more applications are starting to support it. It doesn't really work the same way for installers, but I think I got pretty close, from an end-user's perspective.


Thanks for your time and replies.

I might have confused in posting the question. I agree that the solution should be independent of OS type. Restating the actual problem again,

Need to elevate to admin, only if user has chosen the InstallDir as Program Files, otherwise, need to run normally.

Also, would store the uninstall info in HKLM.


Ok, now you're really not making sense. You cannot store in HKLM without elevation, because you cannot store in HKLM without admin access. If you want an all-user install (that is the same thing as an HKLM install), you must always make sure you have admin rights.


You should present users with a Portable and Standard install checkboxes, instead of guessing what they're trying to do from the path.

If you want a working example, check the Rainmeter installer. Source are available at http://code.google.com/p/rainmeter/s.../Installer.nsi

Not pretty, but it works fine on all systems.