C++ Logon task schedule Error: No Mapping between account names and security ids was done(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
				
        
 
            
        基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
 - 如何通过C程序打开命令提示符Cmd 2022-12-09
 - C++结构和函数声明。为什么它不能编译? 2022-11-07
 - 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
 - 如何在 C++ 中初始化静态常量成员? 2022-01-01
 - 在 C++ 中计算滚动/移动平均值 2021-01-01
 - 这个宏可以转换成函数吗? 2022-01-01
 - 常量变量在标题中不起作用 2021-01-01
 - 如何检查GTK+3.0中的小部件类型? 2022-11-30
 - 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				