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
基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01