开发者

Programmatically creating/deleting tasks for task scheduler

I'm trying to create a task (开发者_Python百科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 ?


It's the ITaskDefinition::Principal property. Set RunLevel in IPrincipal to TASK_RUNLEVEL_HIGHEST.


Here is an example on MSDN.


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;
}


You may wish to explore MSDN Task Scheduler Reference. Also, check Schtasks.exe.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜