c++ - NetUserGetInfo 失败

标签 c++ windows winapi

我正在使用以下代码来运行 NetUserGetInfo功能:

bool MyGetComputerName(std::wstring &ComputerName) {
    bool bReturn=false;
    WCHAR ComputerNameBuffer[MAX_COMPUTERNAME_LENGTH+1]={0};
    DWORD dwComputerNameLength=MAX_COMPUTERNAME_LENGTH+1;
    DWORD dwReturn=GetComputerNameExW(ComputerNameNetBIOS,ComputerNameBuffer,&dwComputerNameLength);
    if(dwReturn) {
        ComputerName=std::wstring(ComputerNameBuffer);
        bReturn=true;
    }
    return bReturn;
}
std::wstring ComputerName;
MyGetComputerName(ComputerName);
USER_INFO_1003* pUserInfo=0;    
NetUserGetInfo(ComputerName.c_str(),L"Gast",1003,reinterpret_cast<LPBYTE*>(&pUserInfo));

函数 NetUserGeInfo 失败并返回错误 124。GetLastError 返回错误 997。 我做错了什么?

最佳答案

NetUserGetInfo 的第三个参数完全无效,这就是它返回错误 124 (ERROR_INVALID_LEVEL) 的原因。

传递the documentation中指定范围内的数字对于 level 参数,如果您希望它起作用。在这种情况下,您应该传递值 1。

关于c++ - NetUserGetInfo 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44196549/

相关文章:

c++ - GDI+ 多线程绘图

c++ - 我在哪里可以找到一个好的 boost 引用?

c++ - 创建动态二维数组

c++ - 输入验证无限循环C++

c++ - 为什么在向上转换后调用派生类的虚方法?

java - Windows图形命令在java中的实现

windows - Unix UID 与 Windows SID - 为什么?

python - Linux下将pyw文件导入为模块

python - 尝试在 python 中的文本文件中写入复制的数据

c++ - 如何用 C++ 为 Windows 编写屏幕保护程序?