title: Problems with scheduled task using ITaskScheduler, ITask interfaces
body: <p>The code below executes without any error, but task didn't executed and I didn't see it in control panel . Please help</p>
  
  <pre><code>HRESULT CreateOnceActionTask(const wchar_t* taskName, const wchar_t* programPath, const wchar_t* params)
  {
      HRESULT hr = S_OK;
  
      CComPtr&lt;ITaskScheduler&gt; taskScheduler;
      if(FAILED(hr = CoCreateInstance(CLSID_CTaskScheduler, NULL, CLSCTX_INPROC_SERVER,   IID_ITaskScheduler, (void**)&amp;taskScheduler)))
          ReturnErrorMsg(hr, L"Failed to get IID_ITaskScheduler");
  
      // create task
      CComPtr&lt;ITask&gt; task;
      if(FAILED(hr = taskScheduler-&gt;NewWorkItem(taskName, CLSID_CTask, IID_ITask, (IUnknown**)&amp;task)))
      {
          //if(FAILED(hr = taskScheduler-&gt;Activate(taskName, IID_ITask, (IUnknown**) &amp;task)))
          ReturnErrorMsg(hr, L"Failed to create task");
  
          //taskScheduler-&gt;Delete(taskName);
  
          //return S_OK;
      }
  
      if(FAILED(hr = task-&gt;SetApplicationName(programPath)))
          ReturnErrorMsg(hr, L"Failed to set SetApplicationName");
  
      if(FAILED(hr = task-&gt;SetParameters(params)))
          ReturnErrorMsg(hr, L"Failed to set SetParameters");
  
      if(FAILED(hr = task-&gt;SetTaskFlags(TASK_FLAG_DELETE_WHEN_DONE)))
          ReturnErrorMsg(hr, L"Failed to set task flags");
  
      // save task
      CComPtr&lt;IPersistFile&gt; persistTask;  
      if(FAILED(hr = task-&gt;QueryInterface(IID_IPersistFile, (void **)&amp;persistTask)))
          ReturnErrorMsg(hr, L"Failed to save task with IPersistFile");   
  
      if(FAILED(hr = persistTask-&gt;Save(NULL,TRUE)))
          ReturnErrorMsg(hr, L"Failed to save task with IPersistFile");
  
      // create trigger
      CComPtr&lt;ITaskTrigger&gt; taskTrigger;
      CComPtr&lt;IPersistFile&gt; persistTrigger = NULL;    
      WORD wTrigNumber = 0;
  
      if (FAILED(hr = task-&gt;CreateTrigger(&amp;wTrigNumber, &amp;taskTrigger)))
          ReturnErrorMsg(hr, L"Failed to createTrigger");
  
      // create trigger description
      TASK_TRIGGER triggerStruct = {0};
      ZeroMemory ( &amp;triggerStruct, sizeof (TASK_TRIGGER) );
      triggerStruct.cbTriggerSize = sizeof (TASK_TRIGGER);
      triggerStruct.TriggerType = TASK_TIME_TRIGGER_ONCE;
  
      // 10 minutes from now
      COleDateTime oDate = COleDateTime::GetCurrentTime() + COleDateTimeSpan(0, 0, 1, 0);
  
      triggerStruct.wBeginYear    = oDate.GetYear();
      triggerStruct.wBeginMonth   = oDate.GetMonth();
      triggerStruct.wBeginDay     = oDate.GetDay();
      triggerStruct.wStartHour    = oDate.GetHour();
      triggerStruct.wStartMinute  = oDate.GetMinute();
  
  
      // associate the trigger with the task
      if (FAILED(hr = taskTrigger-&gt;SetTrigger(&amp;triggerStruct)))
          ReturnErrorMsg(hr, L"Failed to set trigger for the task");
  
      if (FAILED(hr = task-&gt;QueryInterface(IID_IPersistFile, (void **) &amp;persistTrigger)))
          ReturnErrorMsg(hr, L"Failed to get IPersistFile for trigger");
  
      if (FAILED(hr = persistTrigger-&gt;Save(NULL, FALSE)))
          ReturnErrorMsg(hr, L"Failed to save trigger");
  
      if (FAILED(hr = task-&gt;Run()))
          ReturnErrorMsg(hr, L"Failed to run task");
  
      return S_OK;
  }
  </code></pre>