Skip to content
⌘ NSIS Forum Archive

Use !define conditionally

14 posts

HSorgYves#

Use !define conditionally

I want to use the !define UMUI_ALTERNATIVESTARTMENUPAGE_SETSHELLVARCONTEXT statement only if the current user has administrator priviledges. How is this possible?

Thanks,
Yves
HSorgYves#
I can and I do, but that only influences some directory variables not the page displayed by UMUI...

I am even using
!define UMUI_DEFAULT_SHELLVARCONTEXT $UMUI_DEFAULT_SHELLVARCONTEXT 
and then setting $UMUI_DEFAULT_SHELLVARCONTEXT conditionally, but this method doesn't work for
!define UMUI_ALTERNATIVESTARTMENUPAGE_SETSHELLVARCONTEXT 
as it has no argument.
SuperPat#
I would try to implement this feature soon.
The method that I will use is to try to create a file in the Program Files to determine if the application has administrator rights and if this is not the case, disable radio buttons on the start menu page.
Unless you have a better method for determining the level?
HSorgYves#
I am currently using:
xtInfoPlugin::IsAdministrator
Pop $0
StrCmp $0 "true" 
Something like:
!define UMUI_ALTERNATIVESTARTMENUPAGE_SETSHELLVARCONTEXT true|false 
would thus be enough. You could make such an argument optional and thus not break backward compatibility.

Best Regards,
Yves
redxii#
Originally posted by SuperPat
Unless you have a better method for determining the level?
UserInfo::GetAccountType from UserInfo.dll already included in NSIS. http://nsis.sourceforge.net/IsUserAdmin
SuperPat#
Originally posted by redxii
UserInfo::GetAccountType from UserInfo.dll already included in NSIS. http://nsis.sourceforge.net/IsUserAdmin
I think this function does not return the right answer on a windows Vista/7 with a administrateur account if the RequestExecutionLevel is set as user?
redxii#
Well, even if the account is an Administrator in UAC approval mode, if they don't elevate the setup they can't create shortcuts for all users anyway, only for themselves and it's as if they are non-admins.

UserInfo returns the right answer for what privileges the installer has. You don't want to use GetOriginalAccountType to see that they are really an administrator, the installer isn't running elevated, and assume that the context should be set to 'all'.
HSorgYves#
I have tested this on Vista. If "RequestExecutionLevel user" is set, UserInfo::GetAccountType will not return Admin, but the user has no write acces to Program Files for example, so the answer is correct as redxii says.

Best Regards,
Yves
HSorgYves#edited
Problem solved in today's release. Thanks for your quick development!

Best Regards,
Yves