source: oup/releases/0.30a/TFileTypeRegistration/IsAdmin.inc@ 205

Last change on this file since 205 was 33, checked in by alloc, 18 years ago
File size: 2.4 KB
Line 
1function GetAdminSid: PSID;
2const
3 // bekannte SIDs ... (WinNT.h)
4 SECURITYNTAUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
5 // bekannte RIDs ... (WinNT.h)
6 SECURITYBUILTINDOMAINRID: DWORD = $00000020;
7 DOMAINALIASRIDADMINS: DWORD = $00000220;
8begin
9 Result := nil;
10 AllocateAndInitializeSid(SECURITYNTAUTHORITY,
11 2,
12 SECURITYBUILTINDOMAINRID,
13 DOMAINALIASRIDADMINS,
14 0,
15 0,
16 0,
17 0,
18 0,
19 0,
20 Result);
21end;
22
23function IsAdmin: LongBool;
24var
25 TokenHandle : THandle;
26 ReturnLength : DWORD;
27 TokenInformation : PTokenGroups;
28 AdminSid : PSID;
29 Loop : Integer;
30 wv : TOSVersionInfo;
31begin
32 wv.dwOSVersionInfoSize := sizeof(TOSversionInfo);
33 GetVersionEx(wv);
34
35 Result := (wv.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);
36
37 if(wv.dwPlatformId = VER_PLATFORM_WIN32_NT) then
38 begin
39 TokenHandle := 0;
40 if OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, TokenHandle) then
41 try
42 ReturnLength := 0;
43 GetTokenInformation(TokenHandle, TokenGroups, nil, 0, ReturnLength);
44 TokenInformation := GetMemory(ReturnLength);
45 if Assigned(TokenInformation) then
46 try
47 if GetTokenInformation(TokenHandle, TokenGroups,
48 TokenInformation, ReturnLength, ReturnLength) then
49 begin
50 AdminSid := GetAdminSid;
51 for Loop := 0 to TokenInformation^.GroupCount - 1 do
52 begin
53 if EqualSid(TokenInformation^.Groups[Loop].Sid, AdminSid) then
54 begin
55 Result := True; break;
56 end;
57 end;
58 FreeSid(AdminSid);
59 end;
60 finally
61 FreeMemory(TokenInformation);
62 end;
63 finally
64 CloseHandle(TokenHandle);
65 end;
66 end;
67end;
68
69function WVersion: string;
70var
71 OSInfo: TOSVersionInfo;
72begin
73 Result := '3X';
74 OSInfo.dwOSVersionInfoSize := sizeof(TOSVERSIONINFO);
75 GetVersionEx(OSInfo);
76 case OSInfo.dwPlatformID of
77 VER_PLATFORM_WIN32S: begin
78 Result := '3X';
79 Exit;
80 end;
81 VER_PLATFORM_WIN32_WINDOWS: begin
82 Result := '9X';
83 Exit;
84 end;
85 VER_PLATFORM_WIN32_NT: begin
86 Result := 'NT';
87 Exit;
88 end;
89 end; //case
90end;
Note: See TracBrowser for help on using the repository browser.