Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ .evt文件中的WinAPI LookupAccountSid_C++_Winapi_Event Log_Sid - Fatal编程技术网

C++ .evt文件中的WinAPI LookupAccountSid

C++ .evt文件中的WinAPI LookupAccountSid,c++,winapi,event-log,sid,C++,Winapi,Event Log,Sid,我正在尝试从.evt文件(事件日志)获取用户SID的用户帐户名。到目前为止,我已经成功地读取了该文件,并且可以访问记录事件时活动用户的SID 要从该SID获取用户名,我将使用LookupAccountSid函数: wstring userNameFromSid(SID userSid,wstring computerName) { DWORD size = 256; wchar_t * buff = (wchar_t*)mallo

我正在尝试从.evt文件(事件日志)获取用户SID的用户帐户名。到目前为止,我已经成功地读取了该文件,并且可以访问记录事件时活动用户的SID

要从该SID获取用户名,我将使用LookupAccountSid函数:

wstring userNameFromSid(SID  userSid,wstring computerName)
        {
            DWORD size = 256;
            wchar_t * buff = (wchar_t*)malloc(sizeof(wchar_t)*size);
            wchar_t * buffDomain = (wchar_t*)malloc(sizeof(wchar_t)*size);
            SID_NAME_USE SidType;
            wstring result;
            SID tmpSid = userSid;

            if(LookupAccountSid(computerName.c_str(), &tmpSid, buff, &size, buffDomain, &size, &SidType )){
                result= buff;
            }
            else
            { 
                /*Here some code to print error in a Message box*/
            }

            free(buff);
            free(buffDomain);
            return result;
        }
当我尝试使用本地的.evt文件时,这很好,但我的许多.evt文件都来自远程计算机,这就是问题所在。事实上,当我尝试使用远程计算机名时,我会得到一个映射的错误\u NONE\u代码。
经过无数次的研究,我仍然无法解决这个问题(这开始让人恼火)

注:
我尝试使用一个随机错误的计算机名来改进问题,但我得到了一个错误1722:rpc服务器不可用,因此我能够连接rpc(当我给出正确的名称时)


提前感谢您,

您对多个输入/输出参数使用了相同的
大小
变量。不要那样做。使用单独的变量代替。如果
computerName
为空,您也不考虑

试试这个:

static const DWORD MAX_BUFF_SIZE = 256;

wstring userNameFromSid(SID userSid, wstring computerName)
{
    wchar_t buffName[MAX_BUFF_SIZE];
    DWORD buffNameSize = MAX_BUFF_SIZE;
    wchar_t buffDomain[MAX_BUFF_SIZE];
    DWORD buffDomainSize = MAX_BUFF_SIZE;
    SID_NAME_USE SidType;

    if (LookupAccountSid(!computerName.empty() ? computerName.c_str() : NULL, &userSid, buffName, &buffNameSize, buffDomain, &buffDomainSize, &SidType))
    {
        return buffName;
    }

    /*Here some code to print error in a Message box*/
    return L"";
}

SID仅在创建它们的域上有效。如果“远程”机器不是域的一部分,那么就没有机会从该号码中检索任何内容。通过选择假用户名来缓慢前进,这样生成的输出是可读的。@HansPassant你说得对,问题是我收到的SID实际上是Active Directory SID,我想。因此,它们不是在远程计算机上注册的,而是在ldap服务器上注册的。我会把重点放在ldap请求和SID研究上。你的代码肯定比我的更可靠、更干净。如果第一次调用大小为1的
LookupAccountSid()
,并将realloc
buffName
buffDomain
的大小设置为正确的大小,则更安全。