C++ 登录任务计划错误:未完成帐户名称和安全 I

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

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

问题描述

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

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

我正在关注 本微软教程.

但是我在将任务保存到根文件夹时遇到了问题.这里:

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"Builtin\Administrators") 替换为 _variant_t(L"S-1-5-32-544") 到 NULL out语言硬编码问题,仍然没有运气.

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.

我怎样才能让它发挥作用?

How can I make it work?

推荐答案

我怀疑您拥有的演示代码是 XP 时代的,并且尚未更新以匹配 Vista/Win7 规则.

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

我在设置登录触发器后更新了示例以设置 LUA 设置,它似乎有效:

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"DOMAINusername"));
    if (FAILED(hr))
    {
        printf("
Cannot 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("
Cannot 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 之间的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:C++ 登录任务计划错误:未完成帐户名称和安全 I

基础教程推荐