Jump to content
  • Advertisement
Sign in to follow this  
gretty

Retrieving a scheduled task from the Task Scheduler

This topic is 2805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I am using/learning the Windows Task Scheduler in win32 C++. I am attempting to retrieve a task object (for a task that exists) but it continually fails & returns the error COR_E_FILENOTFOUND 0x80070002 = The task does not exist What do you think is going wrong? I know this task exists because I create it (& it does what its supposed to do, open an app at specified time). Maybe the task name I use to retrieve the ITask object is not correct? The status (priority?) of the task I create is == 3 (if that info helps).

The code I use to create a task is exactly the same as the example code from msdn, the task name is "MyTaskSascha". Is there anything wrong with my code to retrieve an existing task (I believe the task I am trying to retrieve is not considered "Running" but "Scheduled" so that maybe the problem?):


bool RetrieveTask( std::string taskName )
{
// Post:

ITaskScheduler *taskSched = NULL;
ITask *task = NULL;
HRESULT hr = S_OK;
HRESULT taskStatus = NULL;

LPCWSTR wTaskName;
wTaskName = L"MyTestSascha";

/// Initialise COM library & obtain Task Scheduler object

hr = CoInitialize( NULL );

if ( FAILED(hr) )
{
printf( "Failed to coinitialise hresult \n" );
return false;
}

hr = CoCreateInstance( CLSID_CTaskScheduler, NULL, CLSCTX_INPROC_SERVER,
IID_ITaskScheduler, (void**) &taskSched );

if ( FAILED(hr) )
{
printf( "Failed to create instance \n" );
CoUninitialize();
return false;
}

/// Obtain task object

hr = taskSched -> Activate( wTaskName, IID_ITask, (IUnknown**) &task );
taskSched -> Release();

std::cout << wTaskName << std::endl;
printf( "%s \n", wTaskName );

if ( FAILED(hr) )
{
// COR_E_FILENOTFOUND E_INVALIDARG E_OUTOFMEMORY SCHED_E_UNKNOWN_OBJECT_VERSION
if ( hr == 0x80070002 ) { std::cout << "The task does not exist \n"; }
else if ( hr == 0x80000003 ) { std::cout << "The pwszName parameter is not valid \n"; }
else if ( hr == 0x80070057 ) { std::cout << "A memory allocation failed \n"; }
else if ( hr == 0x80041313 ) { std::cout << "The task object version is either unsupported or invalid \n"; }
printf( "Failed retrieving task object %x \n", hr );
CoUninitialize();
return false;
}



Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!