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

  1. unit NTGetUserInfo;
  2.  
  3. interface
  4.  
  5. uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
  6.  
  7. type
  8.   TNTGetUserInfo = class(TComponent)
  9.   private
  10.     { Private declarations }
  11.     FUserName:String;
  12.     FServer:String;
  13.     FFullName:String;
  14.     FComment:String;
  15.     FFlags:DWORD;
  16.     FUserID:DWORD;
  17.   protected
  18.     { Protected declarations }
  19.   public
  20.     { Public declarations }
  21.   published
  22.     { Published declarations }
  23.     property Server:string read FServer write FServer;
  24.     property UserName:String read FUserName write FUserName;
  25.     property FullName:String read FFullName;
  26.     property Comment:String read FComment;
  27.     property Flags:DWORD read FFlags;
  28.     property UserID:DWORD read FUserID;
  29.     function Execute:LongInt;
  30.   end;
  31.  
  32. Type USER_INFO_20=record
  33.     usri20_name:LPWSTR;    usri20_full_name:LPWSTR;    usri20_comment:LPWSTR;    usri20_flags:DWORD;    usri20_user_id:DWORD;End;
  34.  
  35. function NetUserGetInfo(Server:PWideChar;UserName:PWideChar;Level:DWORD;Buffer:Pointer):LongInt; stdcall; external 'netapi32.dll';
  36.  
  37. procedure Register;
  38.  
  39. implementation
  40.  
  41. function TNTGetUserInfo.Execute:LongInt;
  42. var TheUser:Array[0..255] Of WideChar;
  43.     TheServer:Array[0..255] Of WideChar;
  44.     MyInfo:USER_INFO_20;
  45.     MyPtr:Pointer;
  46. begin
  47.      MyPtr:=nil;
  48.      StringToWideChar(FUserName,@TheUser,255);
  49.      If FServer<>'' Then
  50.      Begin
  51.           StringToWideChar(FServer,@TheServer,255);
  52.           Result:=NetUserGetInfo(@TheServer,@TheUser,20,@MyPtr);
  53.      End Else
  54.      Begin
  55.           Result:=NetUserGetInfo(nil,@TheUser,20,@MyPtr);
  56.      End;
  57.      If MyPtr<>nil Then
  58.      Begin
  59.           MyInfo:=USER_INFO_20(MyPtr^);
  60.           FFullName:=WideCharToString(MyInfo.usri20_full_name);
  61.           FComment:=WideCharToString(MyInfo.usri20_comment);
  62.           FFlags:=MyInfo.usri20_flags;
  63.           FUserID:=MyInfo.usri20_user_id;
  64.      End Else
  65.      Begin
  66.           FFullName:='';
  67.           FComment:='';
  68.           FFlags:=0;
  69.           FUserID:=0;
  70.      End;
  71. end;
  72.  
  73. procedure Register;
  74. begin
  75.   RegisterComponents('NT Tools - User Management', [TNTGetUserInfo]);
  76. end;
  77.  
  78. end.
  79.