50分!第一的答对的给分。我在网上恭候答案。使用API函数怎么修改NT用户的密码?

bamyl 2000-07-11 09:38:00
我现在是用NET 命令做的,会出现DOS窗体的,好象可以用NETAPI32.DLL来做?
我需要VB的例子,先谢谢各位了!
...全文
138 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wingsun 2000-07-11
  • 打赏
  • 举报
回复
NetUserChangePassword和NetUserSetInfo不过这两个函数都只能在WindowsNT下使用。
liyang 2000-07-11
  • 打赏
  • 举报
回复
#ifndef UNICODE
#define UNICODE
#endif

#include <stdio.h>
#include <windows.h>
#include <lm.h>

int wmain(int argc, wchar_t *argv[])
{
DWORD dwError = 0;
NET_API_STATUS nStatus;
//
// All parameters are required.
//
if (argc != 5)
{
fwprintf(stderr, L"Usage: %s \\\\ServerName UserName OldPassword NewPassword\n", argv[0]);
exit(1);
}
//
// Call the NetUserChangePassword function.
//
nStatus = NetUserChangePassword(argv[1], argv[2], argv[3], argv[4]);
//
// If the call succeeds, inform the user.
//
if (nStatus == NERR_Success)
fwprintf(stderr, L"User password has been changed successfully\n");
//
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);

return 0;
}



VB:

Private Declare Function NetUserChangePassword Lib "Netapi32.dll" (Domain As Any, User As Any, OldPass As Byte, NewPass As Byte) As Long

Private Const NERR_BASE = 2100
Private Const NERR_PasswordTooShort = (NERR_BASE + 145)
Private Const NERR_Success As Long = 0&
Private Const NERR_UserExists = (NERR_BASE + 124)
Private Const NERR_GroupExists = (NERR_BASE + 123)
Private Const NERR_InvalidComputer = (NERR_BASE + 251)
Private Const NERR_NotPrimary = (NERR_BASE + 126)

' Indicates a Windows NT Advanced Server could not be contacted or that
' objects within the domain are protected such that necessary
' information could not be retrieved.
Const ERROR_CANT_ACCESS_DOMAIN_INFO = 1351&

Private Sub Command1_Click()


Dim nStatus As Long
Dim bytOld() As Byte
Dim bytNew() As Byte

bytOld = "oldpwd" & Chr(0)
bytNew = "newpwd123" & Chr(0)
nStatus = NetUserChangePassword("domain", "user", bytOld(0), bytNew(0))
' //
' // If the call succeeds, inform the user.
' //
If nStatus = NERR_Success Then
MsgBox "OK!"
Else
MsgBox "Err!"
End If

End Sub


不过,这好像与server配置有关,有时不能更改。可以查错误码!

1,485

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧