Testare se un installer Nsis è eseguito come administrator
Vista e superiori
È sufficiente usare la direttiva:
RequestExecutionLevel admin
che richiede che l'installer sia lanciato con questi privilegi.
XP e precedenti
Usare il Plugin Userinfo
Sometimes, it's necessary to check if an installer's user has administrative privileges. This simple script checks for that using the "UserInfo" plugin. There's a more sophisticated alternative at http://forums.winamp.com/showthread.php?threadid=195020, but this method seems to work fine. Another example of UserInfo can be found in the NSIS installation directory under \Examples\UserInfo\UserInfo.nsi.
Ad esempio si può inserire il controllo nell funzione .onInit, così non parte nemmeno l'installer:
Function .onInit
...
# 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 "You must install this package with Administrator Rights"
Abort
# otherwise, go on
FunctionEnd