title: Delete a scheduled task using com objects
body: <p>I tried the following code for deleting a scheduled task:</p>
  
  <pre><code>bool deleteTask(std::wstring taskName)
      {
      if (FAILED(CoInitialize(nullptr))) {
          return false;
      }
  
      ITaskScheduler *pITS;
      if (FAILED(CoCreateInstance(CLSID_CTaskScheduler, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskScheduler, (void **)&amp;pITS))) {
          CoUninitialize();
          return false;
      }
  
      HRESULT hr = pITS-&gt;Delete(taskName.c_str());
      pITS-&gt;Release();
      CoUninitialize();
  
      if (FAILED(hr)) {
          if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) {
              wprintf(L"ERROR_FILE_NOT_FOUND");
          }
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>When executing <code>deleteTask(L"exampletask");</code> The method <code>pITS-&gt;Delete</code> returns <code>ERROR_FILE_NOT_FOUND</code> even though  executing <code>schtasks.exe /Query /TN exampletask</code> returns an existing task.<br>
  I also tried this code with the privileges of admin / system / service, and none succeed at finding and deleting the task.</p>
  
  <p>Is there some missing parameter, or maybe a method that should be called?<br>
  Thanks!</p>