Testare se un installer Nsis è eseguito come administrator

From RVM Wiki
Revision as of 17:39, 21 September 2009 by Gabriele.vivinetto (talk | contribs) (New page: ==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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

# name installer
outFile "installer.exe"

# default section start
section
   
    # 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 "not admin: $0"
    return
   
    # otherwise, confirm and return
    messageBox MB_OK "is admin"
   
# default section end
sectionEnd 

Riferimenti