1
2
3; Author: Lilla (lilla@earthlink.net) 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;
12Function IsUserAdmin
13Push $R0
14Push $R1
15Push $R2
16
17ClearErrors
18UserInfo::GetName
19IfErrors Win9x
20Pop $R1
21UserInfo::GetAccountType
22Pop $R2
23
24StrCmp $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'
30StrCpy $R0 "true"
31Goto Done
32
33Continue:
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)
36StrCmp $R2 "" Win9x
37StrCpy $R0 "false"
38;MessageBox MB_OK 'User "$R1" is in the "$R2" group'
39Goto Done
40
41Win9x:
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!"
46StrCpy $R0 "true"
47
48Done:
49;MessageBox MB_OK 'User= "$R1"  AccountType= "$R2"  IsUserAdmin= "$R0"'
50
51Pop $R2
52Pop $R1
53Exch $R0
54FunctionEnd
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;
65Function un.IsUserAdmin
66Push $R0
67Push $R1
68Push $R2
69
70ClearErrors
71UserInfo::GetName
72IfErrors Win9x
73Pop $R1
74UserInfo::GetAccountType
75Pop $R2
76
77StrCmp $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'
83StrCpy $R0 "true"
84Goto Done
85
86Continue:
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)
89StrCmp $R2 "" Win9x
90StrCpy $R0 "false"
91;MessageBox MB_OK 'User "$R1" is in the "$R2" group'
92Goto Done
93
94Win9x:
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!"
99StrCpy $R0 "true"
100
101Done:
102;MessageBox MB_OK 'User= "$R1"  AccountType= "$R2"  IsUserAdmin= "$R0"'
103
104Pop $R2
105Pop $R1
106Exch $R0
107FunctionEnd
108
109