2005-12-22 20:45:29 by: h4x0r

使用windowsAPI在系统中添加一个用户

Font Size: Large | Medium | Small
用户加入到administrator组的完整源码,在delphi7平台测试成功,有不对之处请多指正。
unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;

type
 USER_INFO_1 = record
 usri1_name: PWideChar;
 usri1_password: PWideChar;
 usri1_password_age: DWORD;
 usri1_priv: DWORD;
 usri1_home_dir: PWideChar;
 usri1_comment: PWideChar;
 usri1_flags: DWORD;
 usri1_script_path: PWideChar;
 end;
 _LOCALGROUP_MEMBERS_INFO_3 = record
 lgrmi3_domainandname: PWideChar;
 end;

 uBuf1 = ^USER_INFO_1;
 mBuf3 = ^_LOCALGROUP_MEMBERS_INFO_3;

 TForm1 = class(TForm)
 Button1: TButton;
 procedure Button1Click(Sender: TObject);
 private
 { Private declarations }
 public
 { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

function NetUserAdd(
 Server: PWideChar;
 Level: DWORD;
 Buf: pointer;
 ParmError: dword): Longint; stdcall; external 'netapi32.dll';
function NetLocalGroupAddMembers(
 Server, GroupName: PWideChar;
 Level:Cardinal;
 Buf: pointer;
 TotalEntries: Cardinal): Integer; stdcall; external 'netapi32.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
 buf:uBuf1;
 buf3:mBuf3;
begin
 GetMem(buf, sizeof(USER_INFO_1));
 GetMem(buf3, sizeof(_LOCALGROUP_MEMBERS_INFO_3));
 try
 with buf^ do
 begin
 usri1_name := 'h4x0r';//新用户帐号
 usri1_password := 'h4x0r'; //新用户密码
 usri1_password_age := 0;
 usri1_priv := 1;
 usri1_home_dir := 'c:\temp';//设置本地路径
 usri1_comment := 'Delphi程序自动生成的账号';
 usri1_flags := 1;
 usri1_script_path := 'login.txt';//设置登录脚本
 end;
 NetUserAdd(nil, 1, pointer(buf), 0);
 buf3^.lgrmi3_domainandname := 'leitao2';
 NetLocalGroupAddMembers(nil, 'Administrators', 3, pointer(buf3), 1);
 finally
 FreeMem(buf);
 FreeMem(buf3);
 end;
end;

end.

from:大富
Comments Feed Comments Feed: http://www.4evil.org/feed.asp?q=comment&id=404

There is no comment on this article.

Post Comment
Smilies
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
Enable UBB Codes
Auto Convert URL
Show Smilies
Hidden Comment
Username:   Password:   Register Now?
Security Code * Please Enter the Security Code