Archive: Check installer has admin rights or not?


Check installer has admin rights or not?
Hi!

Is there way to get information about installer has administration rights or not?

Problem:
When I try to install program to "Program Files" folder on Windows Vista the following error is shown "Cannot open file for writing: C:\Program Files\program.exe". I dont want my users get such messages. I want they get my message like "You should install program to another folder or run installer with admin rights". What can I do?


The better solution is to check if installer can run with administration run then do it, otherwise notify user about insufficient rights. Is that possible?


Use the included header MultiUser.nsh


I do it like this:

!macro CheckUserRights
!define ID ${__LINE__}
ClearErrors

UserInfo::GetName
IfErrors Win9x_${ID}
Pop $0
UserInfo::GetAccountType
Pop $1

StrCmp $1 "Admin" Win9x_${ID}
StrCmp $1 "Power" Win9x_${ID}

MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "$0, you don't have the required access rights to install this!"
Quit

Win9x_${ID}:
!undef ID
!macroend

Function .onInit
!insertmacro CheckUserRights
FunctionEnd