Windows 函数 "NetUserChangePassword" 在 Windows 10 下不再工作(在 Windows 7 下工作)
Windows function "NetUserChangePassword" is no longer working under Windows 10 (worked under Windows 7)
我正在使用MSDN页面中的以下代码示例来更改用户的网络密码(https://learn.microsoft.com/en-us/windows/win32/api/lmaccess/nf-lmaccess-netuserchangepassword):
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#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 NewPasswordn", 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 successfullyn");
//
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %dn", nStatus);
return 0;
}
在Windows7下,可以使用此程序更改用户的密码。示例:
> NetUserChangePassword.exe \192.168.1.2 TestUser TestPassword TestPassword
> User password has been changed successfully
在Windows10下,完全相同的程序不再工作:
> NetUserChangePassword.exe \192.168.1.2 TestUser TestPassword TestPassword
> A system error has occurred: 5
两台计算机(Win7和Win10(上的安全设置相同,并且防火墙已关闭。关于如何解决这个问题的想法将不胜感激!
如果您正在为Active Directory编程,您可以调用IADsUser::ChangePassword
方法来获得与调用NetUserChangePassword
函数相同的结果。
如果应用程序在运行Active Directory的域控制器上调用NetUserChangePassword函数,则默认ACL仅允许域管理员和帐户操作员调用此函数。
在成员服务器或工作站上,只有管理员和超级用户才能调用此函数。
用户可以更改自己的密码。
在某些情况下,调用NetUserChangePassword函数的进程还必须启用SE_CHANGE_NOTIFY_NAME权限。
因此,您需要检查两个信息:
- 是否使用Active Directory
-
运行程序的帐户是否满足所需权限?例如,要查找帐户所扮演的角色,可以使用以下代码示例(在C#中(。参见
WindowsPrincipal.IsInRole
方法。AppDomain myDomain = Thread.GetDomain(); myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal; Console.WriteLine("{0} belongs to: ", myPrincipal.Identity.Name.ToString()); Console.WriteLine("{0}? {1}.", "Domain Admins", myPrincipal.IsInRole("Domain Admins")); Console.WriteLine("{0}? {1}.", "AccountOperator", myPrincipal.IsInRole(WindowsBuiltInRole.AccountOperator)); Console.WriteLine("{0}? {1}.", "Administrators", myPrincipal.IsInRole(WindowsBuiltInRole.Administrator)); Console.WriteLine("{0}? {1}.", "PowerUser", myPrincipal.IsInRole(WindowsBuiltInRole.PowerUser));
相关文章:
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- 声明C++具有动态大小的数组类型在 Linux 中工作正常,但不能在 Windows 中工作
- 自 Windows 10 20H1 以来,具有单独线程的多个窗口停止工作
- LoadImage 在 Windows 更新后停止工作
- C++程序工作,但 Windows 显示"程序.exe已停止工作"
- 名为DLL的C++windows服务程序工作不正常
- Windows 函数 "NetUserChangePassword" 在 Windows 10 下不再工作(在 Windows 7 下工作)
- ImpersonateLoggedOnUser在windows服务中不工作
- Makefile在Linux中工作,但在Windows下不起作用,在子目录中找不到文件
- C++代码在 Linux 上按预期工作,但在 Windows 上则不然
- Windows API "CreateWindowEx" 在 Python (3.6.8) 64 位使用的 DLL 中工作吗?
- Windows 上的 SDL 2 在音频设备上无法正常工作
- 有没有办法让DisableUserModeCallbackFilter在Windows 10中工作?
- opengl32.lib如何在Windows(仅1.1版本)上工作?它是否真正实现了OpenGL函数
- C++程序使用 mingw 在 Linux 上交叉编译在 MSy2 中工作,但不能直接在 Windows 中工作
- 将Linux打开,读,写,关闭功能以在Windows上工作
- 从2011年开始,必须在2019年开始工作以使此Windows Textbox做出哪些更改
- Git-Bash for Windows 'rm' 是如何工作的?
- 从Windows上的系统工作的服务中获取用户文档文件夹.C++
- strcat 3 char从char []到char *在Windows上工作,但在Cygwin中给出了细分故障