monark
8th July 2011 09:42 UTC
Multi user install issues
Hi,
I'm new to the forum and having a few issues with NSIS that I'm hoping you can help me with.
I'm trying to put together an installer that will install to XP, Vista and Windows 7 but immediately ran into an issue on XP, admin rights are required in order to install my files correctly but unlike Vista and Win7, XP doesn't prompted for an admin password.
To get around this issue I switched to a multi-user install and included
RequestExecutionLevel admin
This then forces the user to log in as administrator first. I thought I was home and dry but then hit the issue that if you install as a single user on XP in the case where the user has admin privileges the uninstaller can't remove the create shorcuts from the start menu. Googling around offered up this solution
SetShellVarContext all
But that then causes the issue that you are no longer installing for a single user you are installing for everyone.
So back to square one.
What is the correct way to handle installing on XP as administrator?
Is the solution to only offer install for everyone? And if that is the case how do you do that? I'm currently just using the multi-user macro
!define MULTIUSER_EXECUTIONLEVEL Admin
!define MULTIUSER_MUI
!define MULTIUSER_INSTALLMODE_COMMANDLINE
!include "MultiUser.nsh"
!include "MUI2.nsh"
!insertmacro MULTIUSER_PAGE_INSTALLMODE
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
Thanks for any help in advance...
MSG
8th July 2011 09:54 UTC
Originally posted by monark
XP doesn't prompted for an admin password.
To get around this issue I switched to a multi-user install and included
RequestExecutionLevel admin
This then forces the user to log in as administrator first.
This is not correct. Requestexecutionlevel does NOTHING on windows xp. It only does something on Vista and newer with UAC turned on. You need to use the userinfo plugin to verify access level (in .onInit for example), and throw an error when it's not admin (and then quit the installer).
Originally posted by monark
If you install as a single user on XP in the case where the user has admin privileges the uninstaller can't remove the create shorcuts from the start menu.
This isn't true. You just need to make sure that you also verify admin access in the uninstaller (use un.onInit function). The setshellvarcontext all needs to be done either way, because admin-only installers should always install for all users. That's how Windows is designed.
Long story short: Don't use the multiuser macros. If you need admin, install for all users. If not, install for single user.
monark
8th July 2011 10:02 UTC
Long story short: Don't use the multiuser macros. If you need admin, install for all users. If not, install for single user.
Seems to be the same conclusion I came too which is something I suppose.
Requestexecutionlevel does NOTHING on windows xp
Hmmm doesn't seem to be my experience. If it's not that line something in the multi user macro does force the installer to quit if you are not admin, which is what I need.
And it started happening the same time I added that line.... but it's not important really how it happens, it happens.
This is my uninstall function currently
Function un.onInit
!insertmacro MULTIUSER_UNINIT
FunctionEnd
This appears to ignore
RequestExecutionLevel admin
What do I need to add to that to force a request in XP, as far as I found so far nothing will do that.
monark
8th July 2011 10:38 UTC
Now I've switched back to non multi-user install the "You are not a admin" dislog has gone and you are right Requestexecutionlevel does nothing any more, so that must be part of the multi-user macro.
MSG
8th July 2011 11:08 UTC
Like I said, you can use the UserInfo plugin to check for admin acccess, and throw an error if you don't have it. The fancy 'Enter your administrator password here' requires a lot of fancy coding. I guess you could use ShellExecuteEx. But it's a lot of work for a small function - the user can just run as admin themselves.
monark
8th July 2011 11:13 UTC
I'm using this now to test for Admin, seems to work ok
!include "WinVer.nsh"
section
SetShellVarContext all
${If} ${AtMostWinXP}
Call AdminTest
${EndIf}
sectionEnd
Function AdminTest
# call userInfo plugin to get user info. The plugin puts the result in the stack
userInfo::getAccountType
# pop the result from the stack into $0
pop $0
# compare the result with the string "Admin" to see if the user is admin.
# If match, jump 3 lines down.
strCmp $0 "Admin" +3
# if there is not a match, print message and return
messageBox MB_OK "Please log in as Administrator to install these programs."
quit
# otherwise, confirm and return
;messageBox MB_OK "is admin"
FunctionEnd