怎样用NetUserChangePassword修改密码!!!!(100分)

  • 主题发起人 主题发起人 paf
  • 开始时间 开始时间
P

paf

Unregistered / Unconfirmed
GUEST, unregistred user!
直接判断不就可以了么?
function NetUserChangePassword(Domain:PWideChar;
UserName:PWideChar;
OldPassword:PWideChar;
NewPassword:PWideChar): LongInt; stdcall;
external 'netapi32.dll' name 'NetUserChangePassword';

procedure TForm1.Button1Click(Sender: TObject);
begin
NetUserChangePassword(PWideChar(WideString('//COMPUTER')), //计算机名 PWideChar(WideString('username')), //用户
PWideChar(WideString('oldpass')), //旧密码 PWideChar(WideString('newpass'))); //新密码
end;



我已经用最高权限登陆了,有什么办法不用输入旧密码修改密码?
NT 的“设置密码”也是不用旧的密码的啊!
怎样搞!
 
如果你有管理员权限,不要用这个API,而是用NetUserSetInfo
 
我用 NetUserSetInfo 总是出错,错误:87 [参数错误]

function NetUserSetInfo(Server: PWideChar; UserName: PWideChar; Level: DWORD; var Buffer: Pointer;parm_err:LongInt): LongInt; stdcall; external 'netapi32.dll';

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


procedure TForm1.Button10Click(Sender: TObject);
type
buffer = ^USER_INFO_1;
var
buf: buffer;
re:integer;
err:longword;
begin


getmem(buf, sizeof(USER_INFO_1));
with buf^ do
begin
usri1_name := pwidechar(WideString('Guest'));
usri1_password := pwidechar(WideString('123'));
usri1_password_age := 0;
usri1_priv := 1;
usri1_home_dir := pwidechar(WideString(''));
usri1_comment := pwidechar(WideString('我的说明'));
usri1_flags := $10201;
usri1_script_path := pwidechar(WideString(''));
end;



re:=NetUserSetInfo(pwidechar(widestring(ip.text)), pwidechar(widestring('Guest')),1,Pointer(buf),err);

caption :=inttostr(re);
end;


是不是我定议出错了,还是哪里出错了!

 
function NetUserSetInfo(servername: LPCWSTR; username: LPCWSTR; level: DWORD;
buf: Pointer; parm_err: PDWORD): NET_API_STATUS; stdcall;

请到 http://members.chello.nl/m.vanbrakel2/ 下载最新API声明文件,然后看一下就知道怎么回事了。
 
试试这个.应该没有问题的.
unit tmp;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
lbl1: TLabel;
edt1: TEdit;
lbl2: TLabel;
lbl3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function NetUserChangePassword(A:PWideChar;B:PWideChar;c:PWideChar;d:PWideChar):integer;stdcall;external 'Netapi32.dll';

var
Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
oldpass,newpass,username :PWideChar ;
ret:integer;
begin
GetMem(oldpass,50);
GetMem(newpass,50);
GetMem(username,50);
StringToWideChar(Edit1.text,oldpass,length(Edit1.text)+1 );
StringToWideChar(Edit2.text,newpass,length(Edit2.text)+1 );
StringToWideChar(Edt1.text,Username,length(Edt1.text)+1 );
showmessage(WideCharToString(newpass));
ret :=NetUserChangePassword(nil,username,oldpass,newpass);
case (ret) of
ERROR_ACCESS_DENIED:label1.caption:='The user does not have access to the requested information';
//NERR_InvalidComputer:label1.caption:='The computer name is invalid.';
//NERR_NotPrimary:label1.caption:='The operation is allowed only on the primary domain controller of the domain.';
//NERR_UserNotFound:label1.caption:='The user name could not be found.';
//NERR_PasswordTooShort:label1.caption:='The password is shorter than required.';
end;
lbl3.Caption:=inttostr(ret);
end;

end.
 
后退
顶部