home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 April / Chip_2002-04_cd1.bin / zkuste / delphi / kolekce / d56 / NT.ZIP / NTGetUserDomain.pas < prev    next >
Pascal/Delphi Source File  |  1999-06-19  |  1KB  |  55 lines

  1. unit NTGetUserDomain;
  2.  
  3. interface
  4.  
  5. uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
  6.  
  7. type
  8.   TNTGetUserDomain = class(TComponent)
  9.   private
  10.     { Private declarations }
  11.     FUserID:String;
  12.     FDomainName:String;
  13.   protected
  14.     { Protected declarations }
  15.   public
  16.     { Public declarations }
  17.   published
  18.     { Published declarations }
  19.     property UserID:String read FUserID write FUserID;
  20.     property DomainName:String read FDomainName;
  21.     function Execute:Boolean;
  22.   end;
  23.  
  24. procedure Register;
  25.  
  26. implementation
  27.  
  28. function TNTGetUserDomain.Execute:Boolean;
  29. var psnuType:DWord;
  30.     lpszDomain:Array[0..2048] Of Char;
  31.     UserSID:Array[0..1024] Of Char;
  32.     dwDomainLength:DWORD;
  33.     dwSIDBuffSize:DWORD;
  34.     lpszUserName:Array[0..250] Of Char;
  35. begin
  36.      dwDomainLength:=250;
  37.      dwSIDBuffSize:=1024;
  38.      StrPCopy(lpszUserName,FUserID);
  39.      If Not LookupAccountName(nil,lpszUserName,@UserSID,dwSIDBuffSize,lpszDomain,dwDomainLength,psnuType) Then
  40.      Begin
  41.           Result:=False;
  42.      End Else
  43.      Begin
  44.       Result:=True;
  45.           FDomainName:=StrPas(lpszDomain);
  46.      End;
  47. end;
  48.  
  49. procedure Register;
  50. begin
  51.   RegisterComponents('NT Tools - Additional', [TNTGetUserDomain]);
  52. end;
  53.  
  54. end.
  55.