問題描述
我正在嘗試在 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 之間的映射的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!