P
P
polger2019-02-03 17:17:22
C++ / C#
polger, 2019-02-03 17:17:22

How to connect to the task scheduler service?

When executed in the line hr = pService->lpVtbl->Connect(pService, vari, vari, vari, vari); throws an exception: Exception thrown at 0x52F9AFD6 (mstask.dll) in test.exe: 0xC0000005: Access violation while reading at 0xCCCC0000.
I seem to be passing all the parameters correctly. Or not? What is the problem?

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <objidl.h>
#include <wchar.h>
#include <stdio.h>
#include <oleauto.h>
#include <wtypes.h>

#include <taskschd.h>

int main()
{
  VARIANT vari;

  HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, 0, NULL);

  // Создание экземпляра службы задач или чего-то там
  ITaskService *pService = NULL;
  hr = CoCreateInstance(&CLSID_CTaskScheduler, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskScheduler, &pService);

  // Подключение к службе задач
  VariantInit(&vari);
  vari.vt = VT_EMPTY;
  hr = pService->lpVtbl->Connect(pService, vari, vari, vari, vari);

  return 0;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question