给个例子给你,是我copy过来的。unit Unit1;
{ 这是一个演示如何去获取目标NT计算机上用户列表的程序,
由于是为了演示原理,所以没有使用多线程,也没有考虑太高
的强壮性,希望诸位海涵。欢迎和我联系
Vader Yang
ciert@soim.net}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
EdtHostName: TEdit;
Button1: TButton;
Label1: TLabel;
cpDomain: TLabel;
lbAdmin: TLabel;
Label3: TLabel;
Label2: TLabel;
ListBox1: TListBox;
Bevel1: TBevel;
StatusBar1: TStatusBar;
Panel1: TPanel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
SaveDialog1: TSaveDialog;
Options: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure OptionsClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
seedline:String;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
seaNetResource:NETRESOURCE;
seaResult
WORD;
seaAccessBuffer:string[255];
seaAccessBufferLength
WORD;
sidbuffer:string[255];
lpAccessBuffer
Char;
seaSID
SID;
seaSIDlength
WORD;
seaReferencedDomainName:string[255];
seaReferencedDomainNameLength
WORD;
lpReferencedDomainName
Char;
seaSIDnameuse:SID_NAME_USE;
tempPchar
char;
SidSubCount
UCHAR;
i,j:integer;
StoreCount:byte;
tempPDWORD
DWORD;
tempDWORD
WORD;
storeSIDsub: array [0..8] of Integer;
seaSidIdentify
SIDIdentifierAuthority;
newSID
SID;
seaAccountBuffer:String[255];
pAccountName:LPTSTR;
AccountLength
WORD;
BlResult:Boolean;
const
AccountType:array [0..8] of string=('','User','Group','Domain','alias',
'WelknowGroup','Deleted','Invalid','Unknown');
begin
Button1.Enabled:=False;
lpAccessBuffer:=@seaAccessBuffer;
lpReferencedDomainName:=@seaReferencedDomainName;
seaSID:=@sidbuffer;
seaAccessBufferLength:=64;
seaSIDLength:=255;
seaReferencedDomainNameLength:=255;
seaNetResource.dwScope:=RESOURCE_GLOBALNET;
seaNetResource.dwType:=RESOURCETYPE_ANY;
seaNetResource.lpLocalName:=PChar('');
seaNetResource.lpRemoteName:=PChar('//'+EdtHostName.Text+'/IPC$');
seaNetResource.lpProvider:=PChar('');
seaResult:=WNetAddConnection2(seaNetResource,PChar(''),PChar(''),CONNECT_PROMPT);
if seaResult=NO_ERROR then
begin
if LookupAccountName(PChar('//'+EdtHostName.Text),Pchar(seedline),seaSID,seaSIDlength,
lpReferencedDomainName,seaReferencedDomainNamelength,seaSIDnameuse)
then
begin
cpDomain.Caption:=string(lpReferencedDomainName);
seaSidIdentify:=GetSidIdentifierAuthority(seaSID);
SidSubCount:=GetSidSubAuthorityCount(seaSID);
StoreCount:=SidSubCount^;
for i:=0 to Integer(StoreCount)-1 do
begin
tempPDWORD:=GetSidSubAuthority(seaSID,i);
storeSIDsub
:=tempPDWORD^;
end;
//start to get username
pAccountName:=@seaAccountBuffer ;
seaReferencedDomainNameLength:=255;
AccountLength:=255;
storeSIDsub[StoreCount-1]:=500;
if AllocateAndInitializeSid(seaSidIdentify^,SidSubCount^,StoreSidSub[0],
StoreSidSub[1],StoreSidSub[2],StoreSidSub[3],StoreSidSub[4],
StoreSidSub[5],StoreSidSub[6],StoreSidSub[7],newSID) then
begin
if LookupAccountSid(PChar('//'+EdtHostName.Text),newsid,
pAccountName,AccountLength,lpReferencedDomainName,
seaReferencedDomainNameLength,seaSIDnameuse)
then
begin
lbAdmin.Caption:=String(pAccountName);
ListBox1.Items.Add('//'+lpReferencedDomainName+'/'+pAccountName+' Built-in Admin');
end
else
exit;
FreeSid(newSID);
//tempDWORD:=GetLastError;
j:=1;
i:=1000;
while j<=30 do
begin
seaReferencedDomainNamelength:=255;
AccountLength:=255;
StoreSidSub[StoreCount-1]:=i;
AllocateAndInitializeSid(seaSidIdentify^,SidSubCount^,StoreSidSub[0],
StoreSidSub[1],StoreSidSub[2],StoreSidSub[3],StoreSidSub[4],
StoreSidSub[5],StoreSidSub[6],StoreSidSub[7],newSID);
if LookupAccountSid(PChar('//'+EdtHostName.Text),newsid,
pAccountName,AccountLength,lpReferencedDomainName,
seaReferencedDomainNameLength,seaSIDnameuse)
then
begin
if seaSIDnameuse=sidTypeInvalid then j:=j+1
else if seaSIDnameuse<>sidTypeDeletedAccount then
begin
j:=0;
ListBox1.Items.Add('//'+lpReferencedDomainName+
'/'+pAccountName+' '+AccountType[seaSIDnameuse]);
StatusBar1.SimpleText:=pAccountName;
end;
end
else
j:=j+1;
Application.ProcessMessages;
i:=i+1;
FreeSID(newsid);
end;
end;
end
else ShowMessage('Cannot locate sid infomation!');
end
else ShowMessage('Connection Error!');
WNetCancelConnection2(PChar('//'+EdtHostName.Text+'/IPC$'),0,true);
Button1.Enabled:=True;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ListBox1.Items.Clear;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
SaveDialog1.Execute;
if SaveDialog1.FileName<>'' then ListBox1.Items.SaveToFile(SaveDialog1.FileName);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage('如果有任何意见或者咨询'#13#10'请与ciert@soim.net联系');
end;
procedure TForm1.OptionsClick(Sender: TObject);
begin
seedline:=InputBox('Input seed','Input seed(recommend "domain users" or "guest")','guest');
end;
procedure TForm1.FormShow(Sender: TObject);
begin
seedline:='guest';
end;
end.