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

  1. unit NTAddLocalGroup;
  2.  
  3. interface
  4.  
  5. uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
  6.  
  7. type
  8.   TNTAddLocalGroup = class(TComponent)
  9.   private
  10.     { Private declarations }
  11.     FGroup:String;
  12.     FComment:String;
  13.     FServer:String;
  14.   protected
  15.     { Protected declarations }
  16.   public
  17.     { Public declarations }
  18.   published
  19.     { Published declarations }
  20.     property Server:String read FServer write FServer;
  21.     property GroupName:String read FGroup write FGroup;
  22.     property Comment:String read FComment write FComment;
  23.     function Execute:LongInt;
  24.   end;
  25.  
  26. Type LOCALGROUP_INFO_1=record
  27.     lgrpi1_name:LPWSTR;    lgrpi1_comment:LPWSTR;End;
  28.  
  29. function NetLocalGroupAdd(Server:PWideChar;Level:DWORD;Buffer:PChar;ParmError:PChar):LongInt; stdcall; external 'netapi32.dll';
  30.  
  31. procedure Register;
  32.  
  33. implementation
  34.  
  35. function TNTAddLocalGroup.Execute:LongInt;
  36. var
  37.    MyInfo:LOCALGROUP_INFO_1;
  38.    MyGroup:Array[0..255] Of WideChar;
  39.    MyComment:Array[0..255] Of WideChar;
  40.    MyServer:Array[0..255] Of WideChar;
  41. begin
  42.      StringToWideChar(FGroup,@MyGroup,255);
  43.      StringToWideChar(FComment,@MyComment,255);
  44.      MyInfo.lgrpi1_name:=@MyGroup;
  45.      MyInfo.lgrpi1_comment:=@MyComment;
  46.      If FServer<>'' Then
  47.      Begin
  48.           StringToWideChar(FServer,@MyServer,255);
  49.           Result:=NetLocalGroupAdd(@MyServer,1,@MyInfo,nil);
  50.      End Else
  51.      Begin
  52.           Result:=NetLocalGroupAdd(nil,1,@MyInfo,nil);
  53.      End;
  54. end;
  55.  
  56. procedure Register;
  57. begin
  58.   RegisterComponents('NT Tools - Local', [TNTAddLocalGroup]);
  59. end;
  60.  
  61. end.
  62.