У меня есть задача «Автообновление», которая уже существует в планировщике задач, в которой мне нужно контролировать дни в моем графическом интерфейсе.
для запуска задачи.
Я могу прочитать задачу из планировщика, но не могу изменить дни в приведенном ниже коде.
Пожалуйста, помогите мне решить проблему в приведенном ниже коде.
Заранее спасибо.
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if( FAILED(hr) ) {
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}
// Set general COM security levels.
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);
if( FAILED(hr) ) {
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr)) {
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
CoUninitialize();
return 1;
}
// Connect to the task service.
hr = pService->Connect(_variant_t(), _variant_t(),
_variant_t(), _variant_t());
if( FAILED(hr) ) {
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Get the pointer to the root task folder.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder );
pService->Release();
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
CoUninitialize();
return 1;
}
// -------------------------------------------------------
// Get the registered tasks in the folder.
IRegisteredTaskCollection* pTaskCollection = NULL;
hr = pRootFolder->GetTasks( NULL, &pTaskCollection );
pRootFolder->Release();
if( FAILED(hr) )
{
printf("Cannot get the registered tasks.: %x", hr);
CoUninitialize();
return 1;
}
LONG numTasks = 0;
hr = pTaskCollection->get_Count(&numTasks);
if( numTasks == 0 )
{
printf("\nNo Tasks are currently running" );
pTaskCollection->Release();
CoUninitialize();
return 1;
}
printf("\nNumber of Tasks : %d", numTasks );
TASK_STATE taskState;
for(LONG i=0; i < numTasks; i++) {
IRegisteredTask* pRegisteredTask = NULL;
hr = pTaskCollection->get_Item( _variant_t(i+1), &pRegisteredTask );
if( SUCCEEDED(hr) ) {
BSTR taskName = NULL;
std::string string = "AutoUpdate";
hr = pRegisteredTask->get_Name(&taskName);
if( SUCCEEDED(hr) )
{
printf("\nTask Name: %S", taskName);
// covert to std::string
_bstr_t bstr_t(taskName);
std::string str(bstr_t);
if(string.compare(str) == 0){
std::cout <<"\n"<<" inside AutoUpdate " <<"\n";
ITaskDefinition *pDefintion = NULL;
hr = pRegisteredTask->get_Definition(&pDefintion);
if( FAILED(hr) ) {
printf("Cannot get the get_Definition: %x", hr);
CoUninitialize();
return 1;
}
ITriggerCollection *pTriggerCollection = NULL;
hr = pDefintion->get_Triggers(&pTriggerCollection);
if (FAILED(hr)) {
printf("Cannot get the get_Triggers: %x", hr);
pDefintion->Release();
CoUninitialize();
return 1;
}
ITrigger *pTrigger = NULL;
hr = pTriggerCollection->Create(TASK_TRIGGER_DAILY, &pTrigger);
pTriggerCollection->Release();
if (FAILED(hr)) {
printf("Cannot create the Triggers: %x", hr);
pDefintion->Release();
CoUninitialize();
return 1;
}
IDailyTrigger *pDailyTrigger = NULL;
hr = pTrigger->QueryInterface(
IID_IDailyTrigger, (void**)&pDailyTrigger);
pTrigger->Release();
if (FAILED(hr)) {
printf("QueryInterface call on IDailyTrigger failed: %x", hr);
pDefintion->Release();
CoUninitialize();
return 1;
}
hr = pDailyTrigger->put_DaysInterval((short)10);
if (FAILED(hr)) {
printf("QueryInterface call on IDailyTrigger failed: %x", hr);
pDailyTrigger->Release();
pDefintion->Release();
CoUninitialize();
return 1;
}
}
}
}
}
pTaskCollection->Release();
CoUninitialize();
return 0;
Пожалуйста, найдите снимок TaskSchedular
Здесь мне нужно изменить «Повторять каждые» дни. Я могу случайно изменить любые дни из моего пользовательского интерфейса.