| 1 |
|
| 2 |
|
| 3 |
; Author: Lilla ([email protected]) 2003-06-13 |
| 4 |
; function IsUserAdmin uses plugin \NSIS\PlusgIns\UserInfo.dll |
| 5 |
; This function is based upon code in \NSIS\Contrib\UserInfo\UserInfo.nsi |
| 6 |
; This function was tested under NSIS 2 beta 4 (latest CVS as of this writing). |
| 7 |
; |
| 8 |
; Usage: |
| 9 |
; Call IsUserAdmin |
| 10 |
; Pop $R0 ; at this point $R0 is "true" or "false" |
| 11 |
; |
| 12 |
Function IsUserAdmin |
| 13 |
Push $R0 |
| 14 |
Push $R1 |
| 15 |
Push $R2 |
| 16 |
|
| 17 |
ClearErrors |
| 18 |
UserInfo::GetName |
| 19 |
IfErrors Win9x |
| 20 |
Pop $R1 |
| 21 |
UserInfo::GetAccountType |
| 22 |
Pop $R2 |
| 23 |
|
| 24 |
StrCmp $R2 "Admin" 0 Continue |
| 25 |
; Observation: I get here when running Win98SE. (Lilla) |
| 26 |
; The functions UserInfo.dll looks for are there on Win98 too, |
| 27 |
; but just don't work. So UserInfo.dll, knowing that admin isn't required |
| 28 |
; on Win98, returns admin anyway. (per kichik) |
| 29 |
; MessageBox MB_OK 'User "$R1" is in the Administrators group' |
| 30 |
StrCpy $R0 "true" |
| 31 |
Goto Done |
| 32 |
|
| 33 |
Continue: |
| 34 |
; You should still check for an empty string because the functions |
| 35 |
; UserInfo.dll looks for may not be present on Windows 95. (per kichik) |
| 36 |
StrCmp $R2 "" Win9x |
| 37 |
StrCpy $R0 "false" |
| 38 |
;MessageBox MB_OK 'User "$R1" is in the "$R2" group' |
| 39 |
Goto Done |
| 40 |
|
| 41 |
Win9x: |
| 42 |
; comment/message below is by UserInfo.nsi author: |
| 43 |
; This one means you don't need to care about admin or |
| 44 |
; not admin because Windows 9x doesn't either |
| 45 |
;MessageBox MB_OK "Error! This DLL can't run under Windows 9x!" |
| 46 |
StrCpy $R0 "true" |
| 47 |
|
| 48 |
Done: |
| 49 |
;MessageBox MB_OK 'User= "$R1" AccountType= "$R2" IsUserAdmin= "$R0"' |
| 50 |
|
| 51 |
Pop $R2 |
| 52 |
Pop $R1 |
| 53 |
Exch $R0 |
| 54 |
FunctionEnd |
| 55 |
|
| 56 |
|
| 57 |
; function un.IsUserAdmin uses plugin \NSIS\PlusgIns\UserInfo.dll |
| 58 |
; This function is based upon code in \NSIS\Contrib\UserInfo\UserInfo.nsi |
| 59 |
; This function was tested under NSIS 2 beta 4 (latest CVS as of this writing). |
| 60 |
; |
| 61 |
; Usage: |
| 62 |
; Call un.IsUserAdmin |
| 63 |
; Pop $R0 ; at this point $R0 is "true" or "false" |
| 64 |
; |
| 65 |
Function un.IsUserAdmin |
| 66 |
Push $R0 |
| 67 |
Push $R1 |
| 68 |
Push $R2 |
| 69 |
|
| 70 |
ClearErrors |
| 71 |
UserInfo::GetName |
| 72 |
IfErrors Win9x |
| 73 |
Pop $R1 |
| 74 |
UserInfo::GetAccountType |
| 75 |
Pop $R2 |
| 76 |
|
| 77 |
StrCmp $R2 "Admin" 0 Continue |
| 78 |
; Observation: I get here when running Win98SE. (Lilla) |
| 79 |
; The functions UserInfo.dll looks for are there on Win98 too, |
| 80 |
; but just don't work. So UserInfo.dll, knowing that admin isn't required |
| 81 |
; on Win98, returns admin anyway. (per kichik) |
| 82 |
; MessageBox MB_OK 'User "$R1" is in the Administrators group' |
| 83 |
StrCpy $R0 "true" |
| 84 |
Goto Done |
| 85 |
|
| 86 |
Continue: |
| 87 |
; You should still check for an empty string because the functions |
| 88 |
; UserInfo.dll looks for may not be present on Windows 95. (per kichik) |
| 89 |
StrCmp $R2 "" Win9x |
| 90 |
StrCpy $R0 "false" |
| 91 |
;MessageBox MB_OK 'User "$R1" is in the "$R2" group' |
| 92 |
Goto Done |
| 93 |
|
| 94 |
Win9x: |
| 95 |
; comment/message below is by UserInfo.nsi author: |
| 96 |
; This one means you don't need to care about admin or |
| 97 |
; not admin because Windows 9x doesn't either |
| 98 |
;MessageBox MB_OK "Error! This DLL can't run under Windows 9x!" |
| 99 |
StrCpy $R0 "true" |
| 100 |
|
| 101 |
Done: |
| 102 |
;MessageBox MB_OK 'User= "$R1" AccountType= "$R2" IsUserAdmin= "$R0"' |
| 103 |
|
| 104 |
Pop $R2 |
| 105 |
Pop $R1 |
| 106 |
Exch $R0 |
| 107 |
FunctionEnd |
| 108 |
|