修改密码?(20分)

  • 主题发起人 主题发起人 yousf
  • 开始时间 开始时间
Y

yousf

Unregistered / Unconfirmed
GUEST, unregistred user!
The NetUserChangePassword function changes a user's password for a specified network server or domain.

Security Requirements

A server or domain can be configured to require a user to log on before changing the password on a user account. In that case, only members of the Administrators or Account Operators local group or the user himself can change the password for a user account. If logging on is not required, the user can change the password for any user account, as long as the user knows the current password.

NET_API_STATUS NetUserChangePassword(

LPWSTR domainname,
LPWSTR username,
LPWSTR oldpassword,
LPWSTR newpassword
);


Parameters

domainname

Pointer to a null-terminated Unicode string that specifies the name of a remote server or domain. The NetUserChangePassword function changes the user's password on that remote server or domain.
A value of NULL in the domainname parameter specifies the logon domain of the caller.

username

Pointer to a null-terminated Unicode string that specifies a user name. The NetUserChangePassword function changes the password for that user.
A value of NULL in the username parameter specifies the logon user name of the caller.

oldpassword

Pointer to a null-terminated Unicode string that specifies the user's old password on the server or domain.

newpassword

Pointer to a null-terminated Unicode string that specifies the user's new password on the server or domain.



Return Values

If the function is successful, it returns account information and the return value is NET_API_STATUS.
If the function fails, the return value is one of the following error codes.

Value Meaning
ERROR_ACCESS_DENIED The user does not have access to the requested information.
NERR_InvalidComputer The computer name is invalid.
NERR_NotPrimary The operation is allowed only on the primary domain controller of the domain.
NERR_UserNotFound The user name could not be found.
NERR_PasswordTooShort The password is shorter than required.

上面摘自DELPHI帮助,怎么判断这个函数的返回值是属于哪一类?
有没有办法在98里实现局域网用户密码修改?
 
直接判断不就可以了么?
function NetUserChangePassword(Domain:PWideChar;
UserName:PWideChar;
OldPassword:PWideChar;
NewPassword:PWideChar): LongInt; stdcall;
external 'netapi32.dll' name 'NetUserChangePassword';

// 运行平台:Windows NT/2000/XP // Windows 95/98/Me平台:可以用该函数修改用户的Windows登录密码
procedure TForm1.Button1Click(Sender: TObject);
begin
NetUserChangePassword(PWideChar(WideString('//COMPUTER')), //计算机名 PWideChar(WideString('username')), //用户
PWideChar(WideString('oldpass')), //旧密码 PWideChar(WideString('newpass'))); //新密码
end;
 
我判断说语法有错,判断给我看一下,在98下不行!
 
if NetUserChangePassword(PWideChar(WideString('//COMPUTER')), //计算机名 PWideChar(WideString('username')), //用户
PWideChar(WideString('oldpass')), //旧密码 ……)=NERR_InvalidComputer then

有错是怎么回事?
 
Delphi中没有定义这些返回值常量,你需要自己定义。具体值是多少,你查一下
WINDOWS API 的资料吧。

if NetUserChangePassword(PWideChar(WideString('//COMPUTER')), //计算机名
PWideChar(WideString('username')), //用户
PWideChar(WideString('oldpass')), //旧密码
PWideChar(WideString('newpass'))) //新密码
= NERR_InvalidComputer then

begin
end;
 
If the function fails, the return value is one of the following error codes.

Value Meaning
ERROR_ACCESS_DENIED The user does not have access to the requested information.
NERR_InvalidComputer The computer name is invalid.
NERR_NotPrimary The operation is allowed only on the primary domain controller of the domain.
NERR_UserNotFound The user name could not be found.
NERR_PasswordTooShort The password is shorter than required.

这些不是返回值常量吗?
 
是,但是在DELPHI中没有定义
 
procedure TForm1.Button3Click(Sender: TObject);
var nStatus:integer;
begin
if edit4.text=edit5.text then
begin
try
NetUserChangePassword(PWideChar(widestring(ComboBox1.text)),//计算机名
PWideChar(WideString(edit2.text)),//用户
PWideChar(WideString(edit3.text)), //旧密码
PWideChar(WideString(edit4.text)));
nStatus:=NetUserChangePassword(PWideChar(widestring(ComboBox1.text)),
PWideChar(WideString(edit2.text)),
PWideChar(WideString(edit3.text)),
PWideChar(WideString(edit4.text)));
case (nStatus) of
ERROR_ACCESS_DENIED:showmessage('The user does not have access to the requested information.!');
NERR_InvalidComputer:showmessage('The computer name is invalid.');
NERR_NotPrimary:showmessage('The operation is allowed only on the primary domain controller of the domain.!');
NERR_UserNotFound:showmessage('The user name could not be found!');
NERR_PasswordTooShort:showmessage('The password is shorter than required!');
end;

except
showmessage('密码修改不成功!');
end;
end
else
showmessage('新密码输入有错!');
end;

运行时说NERR_InvalidComputer未经声明,怎么声明?
 
const
ERROR_ACCESS_DENIED : Longint = ???
 
tseug:
不明白你的意思,能再详细一点,如果能帮我在98下运行,我会单独给你加100分!
 
找到了定义了,告诉我邮箱,给你发过去。
 
发了吗?怎么还没收到?
 
老兄:现在还没收到,换个地方吧?yousf@163.net
 
其它的搞定了,就是成功与不成功返回值都是86,有谁知道怎么办?
 
接受答案了.
 
后退
顶部