Archive: First time elevating user rights


First time elevating user rights
  I'm not a guru at all, so I have a simple installer which avoids need for admin rights by installing in c:\mydir

Some people are irritated by installation not going into program files, and on Win 7 several different problems appeared in typical corporate environment.

So I decided to finally do something about it. What I need is that installation checks whether user has admin rights and:
- If user is admin, then installer targets program files
- If user is not admin, installer targets c:\mydir AND warns the user that he needs admin password if he wants to change install dir to program files

Everything fine if admin installs into program files or non-admin into c:\mydir

If non-admin wants to (or have to) install into program files (eg. his admin is doing installation for him and wants everything in program files), then I have to use UAC plugin and be careful about what is done as "user" and what is done as "admin" (otherwise, user won't have icon on his desktop nor in start menu, etc).

My questions are:
1. How should I go about checking whether user is admin and changing default target dir accordingly?
2. Did I get the part about UAC plugin right?
3. What happens if non-admin doesn't have access rights to c:\mydir?

Any help greatly appreciated,
Igor


First of all, you should not install to c:\anything in any case, whether you have admin rights or not. In Windows, admin applications are supposed to install themselves to Program Files, and non-admin applications are supposed to install themselves to $LOCALAPPDATA. That's where you need to install to. Not to c:\.

Second, the userlevel icon problem isn't really a problem. The problem is that, once again, you're not doing what Windows demands. If you elevate your installer to admin, you MUST install your application for all users. That's how Windows is designed. Only userlevel installers are supposed to create userlevel icons.

To answer your questions:
1. Use the UserInfo plugin in .onInit to determine whether a user is admin or not.
2. The UAC plugin is only designed to be used for one thing: Allowing an elevated installer to 'Run Installed Application' from the finish page, without giving that application admin access. What you want to do is not impossible, but it's not what the UAC plugin is designed for. (And again, see second point above. Don't create userlevel icons in an elevated installer. All elevated installers should be all-user.)
3. Your installation will fail. See first point above, userlevel installers should only install to $LOCALAPPDATA.


Edit: To create all-user icons, use the setshellvarcontext command.


...
  First that is all possible but it makes your installer more complicated.

If the user has admin rights all will be fine. If not in most cases the admin donĀ“t want that users install things on the machine no matter which directory.

So you should set $PROGRAMFILES always as default directory and request for admin privileges.

InstallDir "$PROGRAMFILES\mysoftware"

>RequestExecutionLevel Admin ;for Vista/7 with UAC on ONLY! For UAC off and Win2k & XP another checkup is required.
The additional checkup for adminrights for Win2k & XP could we do in .onInit function.
For this the easiest way is to use the UserInfo plugin:


onInit

userInfo
::getAccountType
pop$0 ;pop the result into $0
strCmp$0 "Admin" IsAdmin ;compare result with the string "Admin" to see if the user is admin. If Yes then jump to IsAdmin:
>messageBox MB_OK "You need Admin rights to install Blah-Soft"
>quit
IsAdmin:
...
>FunctionEnd
>
Cheers