Hi ,
I found out in a forum that ITaskscheduler's method 'Delete' can be used to delete task from task scheduler;
So i used the following code; Program is executed successfully; But task was not deleted; Where i may be wrong? Please advice me;
CODE
#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>
#include<stdio.h>
#include<iostream>
#pragma comment(lib, "Mstask.lib")
#pragma comment(lib, "ole32.lib")
using namespace std;
int main(int argc, char * argv[])
{
HRESULT hr = S_OK;
ITaskScheduler *pITS;
///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
cout<<"Failed to create object"<<std::endl;
return 1;
}
else
{
cout<<"Object created successfully"<<std::endl;
}
}
else
{
cout<<"Failed to initialize"<<std::endl;
return 1;
}
///////////////////////////////////////////////////////////////////
// Deleting already existing task
///////////////////////////////////////////////////////////////////
pITS->Delete(L"Test Task16");
if(FAILED(hr))
{
cout<<"Test task is not deleted";
}
else
{
cout<<"Test task deleted successfully"<<std::endl;
}
pITS->Release();
return 0;
}