Esempio n. 1
0
void GetTaskDetails2(wchar_t* buf, int bufSize, ITaskScheduler *pITS, LPCWSTR lpcwszTaskName)
{
  
  HRESULT hr = S_OK;
  ITask *pITask = 0;
  wchar_t tmp[500];

  hr = pITS->Activate(lpcwszTaskName, IID_ITask, (IUnknown**) &pITask);
  
  if (FAILED(hr))
  {
     _snwprintf(tmp, sizeof(tmp), L"Failed calling ITaskScheduler::Activate; error = 0x%x\n",hr);
	 wcsncat(buf, tmp, bufSize);
     return;
  }

  LPWSTR lpwszApplicationName;
  hr = pITask->GetApplicationName(&lpwszApplicationName);

  if (FAILED(hr))
  {
     _snwprintf(tmp, sizeof(tmp), L"Failed calling ITask::GetApplicationName error = 0x%x\n", hr);
	 wcsncat(buf, tmp, bufSize);
     lpwszApplicationName = 0;
  }

  LPWSTR lpwszParameters;
  hr = pITask->GetParameters(&lpwszParameters);

  if (FAILED(hr))
  {
     _snwprintf(tmp, sizeof(tmp),  L"Failed calling ITask::GetApplicationName error = 0x%x\n", hr);
	 wcsncat(buf, tmp, bufSize);
	 lpwszParameters = 0;
  }

  pITask->Release();

  if(lpwszApplicationName){
	  _snwprintf(tmp, sizeof(tmp),  L"\t-Exe: %s\n", lpwszApplicationName);
	  wcsncat(buf, tmp, bufSize);
	  CoTaskMemFree(lpwszApplicationName);
  }

  if(lpwszParameters){
	  _snwprintf(tmp, sizeof(tmp),  L"\t-Params: %s\n", lpwszParameters);
	  wcsncat(buf, tmp, bufSize);
	  CoTaskMemFree(lpwszParameters);
  }

}
Esempio n. 2
0
void GetTaskDetails(FILE* f, ITaskScheduler *pITS, LPCWSTR lpcwszTaskName)
{
  
  HRESULT hr = S_OK;
  ITask *pITask = 0;

  hr = pITS->Activate(lpcwszTaskName, IID_ITask, (IUnknown**) &pITask);
  
  if (FAILED(hr))
  {
     fwprintf(f, L"Failed calling ITaskScheduler::Activate; error = 0x%x\n",hr);
     return;
  }

  LPWSTR lpwszApplicationName;
  hr = pITask->GetApplicationName(&lpwszApplicationName);

  if (FAILED(hr))
  {
     fwprintf(f, L"Failed calling ITask::GetApplicationName error = 0x%x\n", hr);
     lpwszApplicationName = 0;
  }

  LPWSTR lpwszParameters;
  hr = pITask->GetParameters(&lpwszParameters);

  if (FAILED(hr))
  {
     fwprintf(f, L"Failed calling ITask::GetApplicationName error = 0x%x\n", hr);
	 lpwszParameters = 0;
  }

  pITask->Release();

  if(lpwszApplicationName){
	  fwprintf(f, L"\t-Exe: %s\n", lpwszApplicationName);
	  CoTaskMemFree(lpwszApplicationName);
  }

  if(lpwszParameters){
	  fwprintf(f, L"\t-Params: %s\n", lpwszParameters);
	  CoTaskMemFree(lpwszParameters);
  }

}
//---------------------------------------------------------------------------
int TTaskScheduler::GetTaskInfo(wstring taskName, TTaskParams& taskParams){
    ITask *pITask = Activate(taskName);

    if(pITask == NULL){
        return 0;
    }

    LPWSTR ppwszAccountName;
    LPWSTR ppwszComment;
    LPWSTR ppwszCreator;
    LPWSTR lpwszApplicationName;
    LPWSTR lpwszParameters;
    LPWSTR lpwszWorkDir;

    DWORD pdwExitCode;
    DWORD pdwRunTime;
    DWORD pdwPriority;

    WORD pwIdleMinutes;
    WORD pwDeadlineMinutes;
    SYSTEMTIME pstLastRun;
    SYSTEMTIME pstNextRun;
    HRESULT phrStatus;


  
    HRESULT hr = pITask->GetAccountInformation(&ppwszAccountName);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
        taskParams.accountName = L"";
    }else{
        taskParams.accountName = ppwszAccountName;
        CoTaskMemFree(ppwszAccountName);
    }

    hr = pITask->GetApplicationName(&lpwszApplicationName);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.appName = lpwszApplicationName;
        CoTaskMemFree(lpwszApplicationName);
    }

    hr = pITask->GetComment(&ppwszComment);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.comments = ppwszComment;
        CoTaskMemFree(ppwszComment);
    }

    hr = pITask->GetCreator(&ppwszCreator);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.creator = ppwszCreator;
        CoTaskMemFree(ppwszCreator);
    }

    hr = pITask->GetExitCode(&pdwExitCode);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.exitCode = pdwExitCode;
    }

    hr = pITask->GetIdleWait(&pwIdleMinutes, &pwDeadlineMinutes);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.deadlineMinutes = pwDeadlineMinutes;
        taskParams.idleMinutes = pwIdleMinutes;
    }

    hr = pITask->GetMaxRunTime(&pdwRunTime);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.maxRuntime = pdwRunTime;
    }

    hr = pITask->GetMostRecentRunTime(&pstLastRun);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.lastRun = pstLastRun;
    }

    hr = pITask->GetNextRunTime(&pstNextRun);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.nextRun = pstNextRun;
    }

    hr = pITask->GetParameters(&lpwszParameters);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.appParameters = lpwszParameters;
        CoTaskMemFree(lpwszParameters);
    }

    hr = pITask->GetPriority(&pdwPriority);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.priority = pdwPriority;
    }

    hr = pITask->GetStatus(&phrStatus);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.status = phrStatus;
    }

    hr = pITask->GetWorkingDirectory(&lpwszWorkDir);
    if (FAILED(hr)){
        sprintf(lastError, "Failed to retreive task info, error = 0x%x\n",hr);
    }else{
        taskParams.workingDirectory = lpwszWorkDir;
        CoTaskMemFree(lpwszWorkDir);
    }

    pITask->Release();
    return 1;

}