我从csdn得不到答案,来这里求助的,听说治理气氛好。关于权限的问题(200分)

  • 主题发起人 主题发起人 suduan
  • 开始时间 开始时间
S

suduan

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获知当前用户是否具有admin权限,<br>或是否属于admin组<br>多谢
 
来自grhunter:<br><br>const <br>SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = <br>(Value: (0, 0, 0, 0, 0, 5)); <br>SECURITY_BUILTIN_DOMAIN_RID = $00000020; <br>DOMAIN_ALIAS_RID_ADMINS = $00000220; <br><br>function IsAdmin: Boolean; <br>var <br>hAccessToken: THandle; <br>ptgGroups: PTokenGroups; <br>dwInfoBufferSize: DWORD; <br>psidAdministrators: PSID; <br>x: Integer; <br>bSuccess: BOOL; <br>begin <br>Result := False; <br>bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, <br>hAccessToken); <br>if not bSuccess then <br>begin <br>if GetLastError = ERROR_NO_TOKEN then <br>bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, <br>hAccessToken); <br>end; <br>if bSuccess then <br>begin <br>GetMem(ptgGroups, 1024); <br>bSuccess := GetTokenInformation(hAccessToken, TokenGroups, <br>ptgGroups, 1024, dwInfoBufferSize); <br>CloseHandle(hAccessToken); <br>if bSuccess then <br>begin <br>AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2, <br>SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, <br>0, 0, 0, 0, 0, 0, psidAdministrators); <br>{$R-} <br>for x := 0 to ptgGroups.GroupCount - 1 do <br>if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then <br>begin <br>Result := True; <br>Break; <br>end; <br>{$R+} <br>FreeSid(psidAdministrators); <br>end; <br>FreeMem(ptgGroups); <br>end; <br>end; <br><br>procedure TForm1.Button1Click(Sender: TObject); <br>begin <br>if isAdmin then <br>begin <br>ShowMessage('以系统管理员身份登录'); <br>end; <br>end.
 
多谢,我先转成vc试一下,在给分
 
const <br>SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = <br>(Value: (0, 0, 0, 0, 0, 5)); <br>这一行常量定义c语言怎么写
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部