NetUserGetInfo失败

时间:2017-05-26 08:01:23

标签: 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。 我做错了什么?

1 个答案:

答案 0 :(得分:2)

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

如果您希望level参数可用,请在the documentation中指定的范围内传递一个数字。在这种情况下,您应该传递值1。

相关问题