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