Exemple #1
0
int __stdcall EnumTasks2(_CollectionPtr *pColl){
  
  int cnt=0;
  HRESULT hr = S_OK;
  ITaskScheduler *pITS;
  wchar_t buf[700];
  char b2[700];

  if(pColl==0 || *pColl == 0) return -4;

  //dont call this from a vb utilized dll no need..
  //hr = CoInitialize(NULL); 
  //if (FAILED(hr)) return hr;

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

  if (FAILED(hr)) return -1;
  
  IEnumWorkItems *pIEnum;
  hr = pITS->Enum(&pIEnum);
  if (FAILED(hr)) return -2;
  
  LPWSTR *lpwszNames;
  DWORD dwFetchedTasks = 0;
  while (SUCCEEDED(pIEnum->Next(TASKS_TO_RETRIEVE, &lpwszNames, &dwFetchedTasks)) && (dwFetchedTasks != 0))
  {

	while (dwFetchedTasks)
    {
	   memset(buf,0, sizeof(buf));
       _snwprintf(buf, sizeof(buf)-1, L"%s\n", lpwszNames[--dwFetchedTasks]);
	   GetTaskDetails2(buf, sizeof(buf)-1 , pITS, lpwszNames[dwFetchedTasks]);
       CoTaskMemFree(lpwszNames[dwFetchedTasks]);
	   
	   memset(b2,0, sizeof(b2));
	   if( wcstombs(b2, buf, sizeof(b2)-1) > 0){
			addStr(*pColl,b2);
	   }
	   cnt++;
    }
    CoTaskMemFree(lpwszNames);
  }
  
  pITS->Release();
  pIEnum->Release();
  return cnt;
}
Exemple #2
0
int __stdcall EnumTasks(char* outPath){
  
  int cnt=0;
  HRESULT hr = S_OK;
  ITaskScheduler *pITS;
 
  //dont call this from a vb utilized dll no need..
  //hr = CoInitialize(NULL); 
  //if (FAILED(hr)) return hr;

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

  if (FAILED(hr)) return 0;
  
  IEnumWorkItems *pIEnum;
  hr = pITS->Enum(&pIEnum);
  if (FAILED(hr)) return 0;
  
  FILE *f = fopen(outPath,"w");
  if(f == NULL) return 0;

  LPWSTR *lpwszNames;
  DWORD dwFetchedTasks = 0;
  while (SUCCEEDED(pIEnum->Next(TASKS_TO_RETRIEVE, &lpwszNames, &dwFetchedTasks)) && (dwFetchedTasks != 0))
  {

	while (dwFetchedTasks)
    {
       fwprintf(f, L"%s\n", lpwszNames[--dwFetchedTasks]);
	   GetTaskDetails(f, pITS, lpwszNames[dwFetchedTasks]);
       CoTaskMemFree(lpwszNames[dwFetchedTasks]);
	   fputc(5,f); //parsing marker..
	   cnt++;
    }
    CoTaskMemFree(lpwszNames);
  }
  
  fclose(f);
  pITS->Release();
  pIEnum->Release();
  return cnt;
}