LogicLib - UserIsAdmin: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
(Fixed broken CheckTokenMembership handling) |
||
| (9 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
{{PageAuthor|Zinthose}} | {{PageAuthor|Zinthose}} | ||
== About == | |||
Library to extend the LogicLib library to allow for testing if the current security context | Library to extend the LogicLib library to allow for testing if the current security context has Administrative rights. | ||
This code is based on the [[IsUserAdmin]] macros done by [[User:Lilla|Lilla]]. | This code is based on the [[IsUserAdmin]] macros done by [[User:Lilla|Lilla]]. | ||
{| style="width:60%; margin:1ex auto; border:4px solid red; background-color:yellow;" | |||
| style="text-align: center; vertical-align: top;" | '''NOTE''' | |||
| This code will only work on windows 2000 and later! | |||
|} | |||
== Source == | |||
<highlight-nsis> | <highlight-nsis> | ||
; ---------------------------- | ; ---------------------------- | ||
| Line 36: | Line 42: | ||
System::Free $0 | System::Free $0 | ||
System::Call 'advapi32::CheckTokenMembership(i n,i r1,*i .r2)i.r3' | System::Call 'advapi32::CheckTokenMembership(i n,i r1,*i .r2)i.r3' | ||
System::Call 'advapi32::FreeSid(i r1) | IntOp $3 $3 && $2 ; Function success AND was a member | ||
System::Call 'advapi32::FreeSid(i r1)' | |||
StrCmp $3 0 0 + | StrCmp $3 0 0 +3 | ||
## User is an Admin | ## User is an Admin | ||
System::Store 'r0 | System::Store 'r3 r2 r1 r0' | ||
Goto `${_f}` | Goto `${_f}` | ||
## User is not an Admin | ## User is not an Admin | ||
System::Store 'r0 | System::Store 'r3 r2 r1 r0' | ||
Goto `${_t}` | Goto `${_t}` | ||
| Line 52: | Line 59: | ||
!endif | !endif | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:User Accounts Related Functions]] | |||
Latest revision as of 19:43, 4 March 2014
| Author: Zinthose (talk, contrib) |
About
Library to extend the LogicLib library to allow for testing if the current security context has Administrative rights.
This code is based on the IsUserAdmin macros done by Lilla.
| NOTE | This code will only work on windows 2000 and later! |
Source
; ---------------------------- ; LogicLib_Ext.nsh ; ---------------------------- ; ; Library to extend the 'LogicLib' library's existing functions. ; !ifndef ___LOGICLIB_EXT__NSH___ !define ___LOGICLIB_EXT__NSH___ !include 'LogicLib.nsh' ; ----------------------- ; UserIsAdmin ; ----------------------- ; ; Example: ; ${If} ${UserIsAdmin} ; DetailPrint "Current user security context has local administrative rights." ; ${Else} ; DetailPrint "Current user security context dose NOT have local administrative rights." ; ${EndIf} ; !macro _UserIsAdmin _a _b _t _f System::Store 'p0 p1 p2 p3' System::Call '*(&i1 0,&i4 0,&i1 5)i.r0' System::Call 'advapi32::AllocateAndInitializeSid(i r0,i 2,i 32,i 544,i 0,i 0,i 0,i 0,i 0,i 0,*i .r1)i.r2' System::Free $0 System::Call 'advapi32::CheckTokenMembership(i n,i r1,*i .r2)i.r3' IntOp $3 $3 && $2 ; Function success AND was a member System::Call 'advapi32::FreeSid(i r1)' StrCmp $3 0 0 +3 ## User is an Admin System::Store 'r3 r2 r1 r0' Goto `${_f}` ## User is not an Admin System::Store 'r3 r2 r1 r0' Goto `${_t}` !macroend !define UserIsAdmin `"" UserIsAdmin ""` !endif