源码如下:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, 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;
  buffer=^User_info_1;
  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';procedure TForm1.Button1Click(Sender: TObject);
var buf:buffer;
    rlt:LongInt;
begin
  try
    getMem(buf,sizeOf(User_info_1));
    buf^.usri1_name :='test';
    buf^.usri1_password :='test';
    buf^.usri1_password_age:=0;
    buf^.usri1_priv :=1;
    buf^.usri1_home_dir :=nil;
    buf^.usri1_comment:=nil;
    buf^.usri1_flags :=1;
    buf^.usri1_script_path :=nil;    rlt:=NetUserAdd(nil,1,pointer(Buf), 0);
    freemem(buf);
  except
  end;
end;
end.
如上一段代码,增加一个用户名test,密码为test,隶属于user组的系统用户,成功;
我把其中的
   buf^usri1_priv:=2;    //隶属为administrator组
不成功. 函数调用后返回值为87  (&H57) 我查了一下,提示错误信息为:线程地址不正确.  //我想加一个隶属于administrator用户组的用户,不知道是不是参数设错,还请高手帮忙啊!!!!
 

解决方案 »

  1.   

    楼主:
        你的代码怎么不行呀?我在2000下跑的,user组的用户也加不上。
      

  2.   

    看看帮助吧,如果你要添加不是user的用户,不能使用NetUserAdd,用NetUserSetInfo代替!
    When you call the NetUserAdd function, this member must be USER_PRIV_USER. When you call the NetUserSetInfo function, this member must be the value returned by the NetUserGetInfo function or the NetUserEnum function. This member can be one of the following values.
      

  3.   

    看看帮助吧,如果你要添加不是user的用户,不能使用NetUserAdd,用NetUserSetInfo代替!
    When you call the NetUserAdd function, this member must be USER_PRIV_USER. When you call the NetUserSetInfo function, this member must be the value returned by the NetUserGetInfo function or the NetUserEnum function. This member can be one of the following values.
      

  4.   

    to firetocher
       那要增加一个隶属于administrator组的用户代码到底应该如何写呢? 我试着用了NetUserSetInfo函数,可是出错,说找不到netapi32.dll的入口. 
       请求帮助..
      

  5.   

    NET_API_STATUS NetUserSetInfo(    LPWSTR servername,
        LPWSTR username,
        DWORD level,
        LPBYTE buf,
        LPDWORD parm_err 
       );
    其实firetoucher(风焱)兄说的很清楚了。具体实现添加Administrator我也不做过!
      

  6.   

    我也不明白为什么不让增加Admiistrator,你试下NetUserSetInfo吧不知行不行
      

  7.   

    老大,搞定!!!MSN上找我!!!