How to display all the tasks in Task scheduler
See the question and my original answer on StackOverflowHere is a sample console app code that will display all tasks recursively, but as I said in the comment, the output will depend if you run this as admin or not.
// include task scheduler lib from code
#pragma comment(lib, "taskschd.lib")
// some useful macros
#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)
#define __WFILE__ WIDEN(__FILE__)
#define HRCHECK(__expr) {hr=(__expr);if(FAILED(hr)){wprintf(L"FAILURE 0x%08X (%i)\n\tline: %u file: '%s'\n\texpr: '" WIDEN(#__expr) L"'\n",hr, hr, __LINE__,__WFILE__);goto cleanup;}}
#define RELEASE(__p) {if(__p!=nullptr){__p->Release();__p=nullptr;}}
#define STARTUP HRESULT hr=S_OK;
#define CLEANUP {cleanup:return hr;}
// forward declaration
HRESULT DumpFolder(ITaskFolder *fld);
int main()
{
STARTUP;
CoInitialize(NULL);
{
CComPtr<ITaskService> svc;
CComPtr<ITaskFolder> fld;
HRCHECK(svc.CoCreateInstance(CLSID_TaskScheduler));
HRCHECK(svc->Connect(CComVariant(), CComVariant(), CComVariant(), CComVariant()));
HRCHECK(svc->GetFolder(CComBSTR(L"\\"), &fld));
HRCHECK(DumpFolder(fld));
}
CoUninitialize();
CLEANUP;
}
HRESULT DumpFolder(ITaskFolder *fld)
{
STARTUP;
CComPtr<IRegisteredTaskCollection> tasks;
CComPtr<ITaskFolderCollection> children;
LONG count;
HRCHECK(fld->GetTasks(TASK_ENUM_HIDDEN, &tasks));
HRCHECK(tasks->get_Count(&count));
// dump out tasks
for (LONG i = 1; i < (count + 1); i++)
{
CComPtr<IRegisteredTask> task;
CComBSTR name;
HRCHECK(tasks->get_Item(CComVariant(i), &task));
HRCHECK(task->get_Name(&name));
wprintf(L"name:'%s'\n", name.m_str);
}
// dump out sub folder
HRCHECK(fld->GetFolders(0, &children));
HRCHECK(children->get_Count(&count));
for (LONG i = 1; i < (count + 1); i++)
{
CComPtr<ITaskFolder> child;
HRCHECK(children->get_Item(CComVariant(i), &child));
// go recursive
HRCHECK(DumpFolder(child));
}
CLEANUP;
}