Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2551 dpurdie 1
!macro IsUserAdmin un
2
    ; Usage:
3
    ;   Call IsUserAdmin
4
    ;   Pop $R0   ; at this point $R0 is "true" or "false"
5
    ;
6
    Function ${un}IsUserAdmin
7
    	Push $R0
8
    	Push $R1
9
    	Push $R2
10
 
11
    	ClearErrors
12
    	UserInfo::GetName
13
    	IfErrors Win9x
14
    	Pop $R1
15
    	UserInfo::GetAccountType
16
    	Pop $R2
17
 
18
    	StrCmp $R2 "Admin" 0 Continue
19
 
20
    	; Observation: I get here when running Win98SE.
21
    	; The functions UserInfo.dll looks for are there on Win98 too,
22
    	; but just don't work. So UserInfo.dll, knowing that admin isn't required
23
    	; on Win98, returns admin anyway.
24
    	; MessageBox MB_OK 'User "$R1" is in the Administrators group'
25
    	StrCpy $R0 "true"
26
    	Goto Done
27
 
28
    	Continue:
29
    	; You should still check for an empty string because the functions
30
    	; UserInfo.dll looks for may not be present on Windows 95. (per kichik)
31
    	StrCmp $R2 "" Win9x
32
    	StrCpy $R0 "false"
33
    	;MessageBox MB_OK 'User "$R1" is in the "$R2" group'
34
    	Goto Done
35
 
36
    	Win9x:
37
    	; comment/message below is by UserInfo.nsi author:
38
    	; This one means you don't need to care about admin or
39
      	; not admin because Windows 9x doesn't either
40
    	;MessageBox MB_OK "Error! This DLL can't run under Windows 9x!"
41
    	StrCpy $R0 "true"
42
 
43
    	Done:
44
    	 ;MessageBox MB_OK 'User= "$R1"  AccountType= "$R2"  IsUserAdmin= "$R0"'
45
 
46
    	 Pop $R2
47
    	 Pop $R1
48
    	 Exch $R0
49
    FunctionEnd
50
!macroend