C ++登录任务计划错误:帐户名和安全ID之间未完成映射 [英] C++ Logon task schedule Error: No Mapping between account names and security ids was done

查看:263
本文介绍了C ++登录任务计划错误:帐户名和安全ID之间未完成映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在Windows 7上使用C ++编写Windows登录触发任务。

I am trying to write a windows Logon trigger task using C++ on Windows 7.

我正在关注此Microsoft教程

但是我在将任务保存到根文件夹时遇到问题。
此处:

But I am facing problem in saving the task to root folder. Here:

//  ------------------------------------------------------
    //  Save the task in the root folder.
    IRegisteredTask *pRegisteredTask = NULL;

    hr = pRootFolder->RegisterTaskDefinition(
            _bstr_t( wszTaskName ),
            pTask,
            TASK_CREATE_OR_UPDATE, 
            _variant_t(L"Builtin\\Administrators"), 
            _variant_t(), 
            TASK_LOGON_GROUP,
            _variant_t(L""),
            &pRegisteredTask);

hr 出现错误的地方: 没有完成帐户名和安全ID之间的映射

Where the hr is getting error : No Mapping between account names and security ids was done

我还尝试替换了 _variant_t( L建筑物管理员) _variant_t(L S-1-5-32-544)可以使语言输出为空硬编码问题,仍然没有运气。

I also tried replacing _variant_t(L"Builtin\\Administrators") with _variant_t(L"S-1-5-32-544") to NULL out language hard coding issue, still No luck.

我如何使其工作?

推荐答案

我怀疑演示代码是XP时代的,尚未进行更新以匹配Vista / Win7规则。

I suspect the demo code you have is XP-era, and hasn't been updated to match the Vista/Win7 rules.

我在设置了登录触发器,它似乎可以正常工作:

I updated the sample to set the LUA settings after setting the logon trigger, and it seems to work:

    hr = pLogonTrigger->put_UserId(_bstr_t(L"DOMAIN\username"));
    if (FAILED(hr))
    {
        printf("\nCannot add user ID to logon trigger: %x", hr);
        CoUninitialize();
        return 1;
    }


    //*** NEW**** Set the LUA settings
    CComPtr<IPrincipal>         pPrincipal;

    hr = pTask->get_Principal(&pPrincipal);
    if (SUCCEEDED(hr))
    {
        hr = pPrincipal->put_RunLevel(TASK_RUNLEVEL_LUA);
    }
    if (SUCCEEDED(hr))
    {
        hr = pPrincipal->put_GroupId(_bstr_t(L"Builtin\\Administrators"));
    }
    if (FAILED(hr))
    {
        printf("\nCannot set runlevel/groupid: %x", hr);
        CoUninitialize();
        return 1;
    }

如果您需要在XP上运行,则 get_Principal 调用将失败,因此请让该失败通过。

If you need it to run on XP, then it's likely that the get_Principal call will fail, so let that failure through.

这篇关于C ++登录任务计划错误:帐户名和安全ID之间未完成映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆