发信人: teleme(PassWord) 
整理人: teleme(2001-07-29 19:39:33), 站内信件
 | 
 
 
//***************以下保存为Unit1.dfm
 object Form1: TForm1
   Left = 209
   Top = 156
   Width = 353
   Height = 446
   Color = clBtnFace
   Font.Charset = GB2312_CHARSET
   Font.Color = clWindowText
   Font.Height = -16
   Font.Name = 'System'
   Font.Style = []
   OldCreateOrder = False
   Position = poDesktopCenter
   OnShow = FormShow
   PixelsPerInch = 96
   TextHeight = 16
   object Bevel1: TBevel
     Left = 0
     Top = 0
     Width = 345
     Height = 113
     Align = alTop
   end
   object Label1: TLabel
     Left = 8
     Top = 40
     Width = 14
     Height = 16
     Caption = '域'
     Font.Charset = DEFAULT_CHARSET
     Font.Color = clWindowText
     Font.Height = -16
     Font.Name = 'System'
     Font.Style = []
     ParentFont = False
   end
   object cpDomain: TLabel
     Left = 112
     Top = 39
     Width = 4
     Height = 16
     Font.Charset = GB2312_CHARSET
     Font.Color = clWindowText
     Font.Height = -16
     Font.Name = 'System'
     Font.Style = []
     ParentFont = False
   end
   object lbAdmin: TLabel
     Left = 112
     Top = 86
     Width = 4
     Height = 16
     Font.Charset = GB2312_CHARSET
     Font.Color = clWindowText
     Font.Height = -16
     Font.Name = 'System'
     Font.Style = []
     ParentFont = False
   end
   object Label3: TLabel
     Left = 8
     Top = 64
     Width = 84
     Height = 16
     Caption = '检查到的帐号'
     Font.Charset = DEFAULT_CHARSET
     Font.Color = clWindowText
     Font.Height = -16
     Font.Name = 'System'
     Font.Style = []
     ParentFont = False
   end
   object Label2: TLabel
     Left = 8
     Top = 13
     Width = 56
     Height = 16
     Caption = '目标主机'
     Font.Charset = GB2312_CHARSET
     Font.Color = clWindowText
     Font.Height = -16
     Font.Name = 'System'
     Font.Style = []
     ParentFont = False
   end
   object EdtHostName: TEdit
     Left = 128
     Top = 8
     Width = 121
     Height = 24
     TabOrder = 0
     Text = '127.0.0.1'
   end
   object Button1: TButton
     Left = 256
     Top = 8
     Width = 75
     Height = 25
     Caption = '开始'
     TabOrder = 1
     OnClick = Button1Click
   end
   object ListBox1: TListBox
     Left = 0
     Top = 113
     Width = 345
     Height = 246
     Align = alClient
     ItemHeight = 16
     TabOrder = 2
   end
   object StatusBar1: TStatusBar
     Left = 0
     Top = 400
     Width = 345
     Height = 19
     Panels = <>
     SimplePanel = True
     SimpleText = '本程序只能在NT上运行。                 For NT only'
   end
   object Panel1: TPanel
     Left = 0
     Top = 359
     Width = 345
     Height = 41
     Align = alBottom
     BevelInner = bvRaised
     BevelOuter = bvLowered
     TabOrder = 4
     object Button3: TButton
       Left = 56
       Top = 8
       Width = 75
       Height = 25
       Caption = '清除'
       TabOrder = 0
       OnClick = Button3Click
     end
     object Button4: TButton
       Left = 200
       Top = 9
       Width = 75
       Height = 25
       Caption = '保存'
       TabOrder = 1
       OnClick = Button4Click
     end
   end
   object Options: TButton
     Left = 256
     Top = 72
     Width = 75
     Height = 25
     Caption = '选项'
     TabOrder = 5
     OnClick = OptionsClick
   end
   object SaveDialog1: TSaveDialog
     DefaultExt = 'txt'
     Filter = 'txt file|*.txt|all files|*.*'
     Options = [ofOverwritePrompt, ofHideReadOnly, ofEnableSizing]
     Left = 160
     Top = 375
   end
 end
 
 
 //***************以下保存为Unit1.pas
 
 unit Unit1;
 {  这是一个演示如何去获取目标NT计算机上用户列表的程序 }
 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;
     Button3: TButton;
     Button4: TButton;
     SaveDialog1: TSaveDialog;
     Options: TButton;
     procedure Button1Click(Sender: TObject);
     procedure Button3Click(Sender: TObject);
     procedure Button4Click(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:DWORD;
     seaAccessBuffer:string[255];
     seaAccessBufferLength:DWORD;
     sidbuffer:string[255];
     lpAccessBuffer:PChar;
     seaSID:PSID;
     seaSIDlength:DWORD;
     seaReferencedDomainName:string[255];
     seaReferencedDomainNameLength:DWORD;
     lpReferencedDomainName:PChar;
     seaSIDnameuse:SID_NAME_USE;
     tempPchar:Pchar;
     SidSubCount:PUCHAR;
     i,j:integer;
     StoreCount:byte;
     tempPDWORD:PDWORD;
     tempDWORD:DWORD;
     storeSIDsub: array [0..8] of Integer;
     seaSidIdentify:PSIDIdentifierAuthority;
     newSID:PSID;
     seaAccountBuffer:String[255];
     pAccountName:LPTSTR;
     AccountLength:DWORD;
     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[i]:=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('连接错误!');
     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.OptionsClick(Sender: TObject);
 begin
      seedline:=InputBox('输入','起始用户(推荐使用 "domain users" 或者 "guest")','guest');
 end;
 
 procedure TForm1.FormShow(Sender: TObject);
 begin
     seedline:='guest';
 end;
 
 end.
 
  ---- fire engine   
 
      | 
 
 
 |