Reputation: 2389
I'm trying to create a task (via C++) that should be executed with highest privileges, although I cannot see in the docs for Task Scheduler how to set that flag (which is available via the Task Scheduler UI).
Ideas ?
Upvotes: 2
Views: 4497
Reputation: 21
Here is the code snippet how to setup run level.
IPrincipal *pPrincipal = NULL;
hr = pTask->get_Principal(&pPrincipal);
if (FAILED(hr))
{
printf("\nCannot get principal pointer: %x", hr);
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return false;
}
// Set up principal run level to the highest one
hr = pPrincipal->put_RunLevel(TASK_RUNLEVEL_HIGHEST);
pPrincipal->Release();
if (FAILED(hr))
{
printf("\nCannot put principal info: %x", hr);
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return false;
}
Upvotes: 2
Reputation: 8463
It's the ITaskDefinition::Principal
property. Set RunLevel
in IPrincipal
to TASK_RUNLEVEL_HIGHEST
.
Upvotes: 3
Reputation: 13035
You may wish to explore MSDN Task Scheduler Reference. Also, check Schtasks.exe.
Upvotes: 0