1 | function GetAdminSid: PSID;
|
---|
2 | const
|
---|
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;
|
---|
8 | begin
|
---|
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);
|
---|
21 | end;
|
---|
22 |
|
---|
23 | function IsAdmin: LongBool;
|
---|
24 | var
|
---|
25 | TokenHandle : THandle;
|
---|
26 | ReturnLength : DWORD;
|
---|
27 | TokenInformation : PTokenGroups;
|
---|
28 | AdminSid : PSID;
|
---|
29 | Loop : Integer;
|
---|
30 | wv : TOSVersionInfo;
|
---|
31 | begin
|
---|
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;
|
---|
67 | end;
|
---|
68 |
|
---|
69 | function WVersion: string;
|
---|
70 | var
|
---|
71 | OSInfo: TOSVersionInfo;
|
---|
72 | begin
|
---|
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
|
---|
90 | end;
|
---|