コード例 #1
0
/**
 * Delete the schedule task.
 * @return 0 if no errors
 */
int deleteScheduleTask() {

    HRESULT hr = S_OK;
    ITaskScheduler* pITS = NULL;
    wstring taskName;

    // Init COM library & create instance for Task scheduler.
    if ((pITS = initScheduleInstance()) == NULL) {
        goto error;
    }

    // Task is associated with current user
    if (getScheduledTaskName(taskName)) {
        goto error;
    }

    //
    // Delete the task (if exists).
    //
    hr = pITS->Delete(taskName.c_str());
    pITS->Release();
    if (FAILED(hr)) {
        if (hr == E_OBJECT_NOT_FOUND) {
            // Not found -> no need to notify.
        }
        else {
            char* msg = readSystemErrorMsg(hr);
            setErrorF(getLastErrorCode(), ERR_SCHED_DELETE, hr, msg);
            delete [] msg;
            goto error;
        }
    }

    LOG.info(INFO_SCHED_TASK_DELETED);
    CoUninitialize();
    return 0;

error:
    LOG.error(getLastErrorMsg());
    CoUninitialize();
    return 1;
}
コード例 #2
0
ファイル: ScheduledTask.cpp プロジェクト: DjPasco/Mag
/*static*/ HRESULT CScheduledTask::DeleteTask ( LPCTSTR szTaskName )
{
HRESULT         hr;
ITaskScheduler* pISched    = NULL;
    
    USES_CONVERSION;

    ASSERT ( AfxIsValidString ( szTaskName ));

    // Validate parameters.

    if ( 0 == lstrlen ( szTaskName ) )
        {
        return E_FAIL;
        }


    // Get an interface to the scheduler.

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

 
    if ( FAILED(hr) )
        {
#ifdef _DEBUG
        TRACE1("CScheduledTask::DeleteTask() - failed to create a task scheduler interface. Return = 0x%08X\n",
               (DWORD) hr );

        // Check if the error was "class not registered".  If so, you don't
        // have the scheduler installed.  I display a nice long message in
        // the debug window, which hopefully explains what's up. :)

        if ( REGDB_E_CLASSNOTREG == hr )
            {
            TRACE0("    The error was REGDB_E_CLASSNOTREG, meaning you don't have the scheduler installed.\n"
                _T("    If you are running 95 or NT 4 with IE 4, you must install the task scheduler from the\n")
                _T("    IE components install page on MS's web site or the IE CD.\n")
                _T("    If you're on 98, NT 5, or 95/NT 4 with IE 5, then something's wrong with your install\n")
                _T("    because the scheduler should always be installed.\n")
                _T("    Note that this class does *NOT* work with the \"AT\" service, which is the default\n")
                _T("    scheduler on NT 4 and earlier.\n") );
            }
#endif  // _DEBUG

        return hr;
        }


    // Delete the task.

    hr = pISched->Delete ( T2COLE ( szTaskName ));
  
    if ( FAILED(hr) )
        {
        TRACE1("CScheduledTask::DeleteTask() - failed to delete task. Return = 0x%08X\n",
               (DWORD) hr );
        }


    pISched->Release();

    return hr;
}
コード例 #3
0
ファイル: CTask.cpp プロジェクト: tuku1185/taskscheduler
/*static*/ HRESULT CTask::DeleteTask ( LPCTSTR szTaskName )
{
HRESULT         hr;
ITaskScheduler* pISched    = NULL;
    
    USES_CONVERSION;

    ASSERT ( AfxIsValidString ( szTaskName ));

    // sprawdz poprawnosc parametrow
    if ( 0 == lstrlen ( szTaskName ) )
        {
        return E_FAIL;
        }


    // Pobierz interfejs
    hr = ::CoCreateInstance (
               CLSID_CTaskScheduler,
               NULL,
               CLSCTX_INPROC_SERVER,
               IID_ITaskScheduler,
               (void **) &pISched );

 
    if ( FAILED(hr) )
        {
#ifdef _DEBUG
        TRACE1("CTask::DeleteTask() - failed to create a task scheduler interface. Return = 0x%08X\n",
               (DWORD) hr );

        // sprawdz czy Task Scheduler jest zainstalowany
        if ( REGDB_E_CLASSNOTREG == hr )
            {
            TRACE0("    The error was REGDB_E_CLASSNOTREG, meaning you don't have the scheduler installed.\n"
                _T("    If you are running 95 or NT 4 with IE 4, you must install the task scheduler from the\n")
                _T("    IE components install page on MS's web site or the IE CD.\n")
                _T("    If you're on 98, NT 5, or 95/NT 4 with IE 5, then something's wrong with your install\n")
                _T("    because the scheduler should always be present.\n")
                _T("    Note that this class does *NOT* work with the \"AT\" service, which is the default\n")
                _T("    scheduler on NT 4 and earlier.\n") );
            }
#endif  // _DEBUG

        return hr;
        }


    // usun zadanie
    hr = pISched->Delete ( T2COLE ( szTaskName ));
  
    if ( FAILED(hr) )
        {
        TRACE1("CTask::DeleteTask() - failed to delete task. Return = 0x%08X\n",
               (DWORD) hr );
        }

	//sprzatamy
    pISched->Release();

    return hr;
}