天天看点

获取本地用户组、组内用户及相关联权限列表

 获取本地用户组、组内用户及相关联权限列表

首先添加AcountManager单元(可以从我的空间htpp://jonychen.ys168.com下载)

uses AcountManager;

下面给出获取本地用户组、组内用户及相关联权限列表调用代码

{

  作者 : JJony

  QQ   : 254706028

  博客 : http://blog.csdn.net/jzj_jony

  空间 :http://jonychen.ys168.com

  AcountManager单元5个导出函数

  //获取帐户对应SID

  function GetAccountSid(const System, AccountName: string; var Sid: PSID): Boolean;

  //枚举用户组或用户权限

  procedure EnumAcountPri(AName: string;list:tstrings);

  //获取本地用户组

  Procedure GetLocalGroups(list : TStrings);

  //获取指定用户组的成员

  procedure GetMembers (GroupName:string;list : TStrings);

  //获取指定用户相关描述

  Function GetUserComment(username:string):string;

}

unit Unit1;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls,AcountManager;

type

  TForm1 = class(TForm)

    Memo1: TMemo;

    Button5: TButton;

    procedure Button5Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button5Click(Sender: TObject);

var

  Gstr,Ustr,Pri:tstrings;

  i,j,k:integer;

begin

  memo1.Clear;

  Gstr:=tstringlist.Create;

  Ustr:=tstringlist.Create;

  Pri:=tstringlist.Create;

try

  GetLocalGroups(Gstr);

for i:=0 to Gstr.Count-1 do

  begin

    memo1.Lines.Add(Gstr[i]);

    EnumAcountPri(Gstr[i],Pri);

    memo1.Lines.Add('    '+Gstr[i]+'组权限:');

    for k:=0 to Pri.Count-1 do

     memo1.Lines.Add('    '+Pri[k]);

    GetMembers(Gstr[i],Ustr);

    for j:=0 to  ustr.Count-1 do

     begin

      memo1.Lines.Add('       组内用户'+inttostr(j+1)+': '+ustr[j]+'-->'+GetUserComment(ustr[j]));

      memo1.Lines.Add('        '+ustr[j]+'用户权限:');

       for k:=0 to Pri.Count-1 do

        memo1.Lines.Add('          '+Pri[k]);

     end;

  memo1.Lines.Add('---------------------------------------------');

  end;

finally

  Gstr.Clear;

  Gstr.Free;

  Ustr.Clear;

  Ustr.Free;

  Pri.Clear;

  Pri.Free;

end;

end;

end.

继续阅读