当前位置:Linux教程 - Linux文化 - 有没有判断用户是否是Administrator的API

有没有判断用户是否是Administrator的API


>>> 此贴的回复 >> http://www.518sf.cn/blog/article.asp?id=55

>>> 此贴的回复 >> function IsAdmin: Boolean; var  hAccessToken: THandle;  ptgGroups: PTokenGroups;  dwInfoBufferSize: DWORD;  psidAdministrators: PSID;  x: Integer;  bSuccess: BOOL; begin  Result := False;  bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,   hAccessToken);  if not bSuccess then  begin   if GetLastError = ERROR_NO_TOKEN then   bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,                  hAccessToken);  end;  if bSuccess then  begin   GetMem(ptgGroups, 1024);   bSuccess := GetTokenInformation(hAccessToken, TokenGroups,                   ptgGroups, 1024, dwInfoBufferSize);   CloseHandle(hAccessToken);   if bSuccess then   begin    AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2,     SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,     0, 0, 0, 0, 0, 0, psidAdministrators);    {$R-}    for x := 0 to ptgGroups.GroupCount - 1 do     if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then     begin      Result := True;      Break;     end;    {$R+}    FreeSid(psidAdministrators);   end;   FreeMem(ptgGroups);  end; end; 

>>> 此贴的回复 >> 呵呵,基础代码,到处都有的 还有一个特别的方法 适合XP/2003的 用MS的LegitCheck COM来做,LegitCheck就是MS WinXP/2003的正版验证系统 其提供的ILegitCheck就有IsAdministrator的函数,呵呵:)