|
|
|
Si una tarea aparentemente no se ejecuta, y auncuando se le cambie la hora
etc. nada,
revisar que su estado no sea activo, lo que significa que se quedó
pegada,
o que es una aplicación interactiva y de pronto está esperando
una respuesta
del usuario. (Esto se vé en el menú del explorador de windows,
al estar en la
carpeta tareas programadasSi una tarea aparentemente no se ejecuta, y auncuando
se le cambie la hora etc. nada,
revisar que su estado no sea activo, lo que significa que se quedó
pegada,
o que es una aplicación interactiva y de pronto está esperando
una respuesta
del usuario. (Esto se vé en el menú del explorador de windows,
al estar en la
carpeta tareas programadas)
Para mas información: buscar Task Scheduler Reference en google
En XP la tarea programada debe llevar la extensión .exe porque sino
al
consultar el menu de arriba "Opciones avanzadas"- Registro, nos
aparece
que hay un error con acceso denegado.
How to troubleshoot scheduled tasks in Windows XP and in Windows
Server 2003
View products that this article applies to. <#appliesto>
Article ID : 308558
Last Review : February 22, 2006
Revision : 2.1
This article was previously published under Q308558
SUMMARY
This step-by-step article describes how to troubleshoot scheduled tasks
in Windows XP and in Windows Server 2003. If scheduled tasks do not run,
you can use several methods to determine the source of the problem.
*Note* Administrators or users with administrator permissions can
configure the Task Scheduler to send a notification when a scheduled
task does not run as you set it to run. To do so, click *Notify Me of
Missed Tasks* on the *Advanced* menu.
Back to the top <#top> Back to the top <#top>
Checking the Task Status
Periodically check the status of scheduled tasks, because sometimes you
may not be aware that a scheduled task did not run. Use the Detail view
in the Scheduled Task window to see the following information about each
task:
*Schedule* - The schedule for the task.
*Next Run Time* - The time and date that the task is next scheduled to run.
*Last Run Time* - The time and date the task was last run.
*Status* - The current status of the task.
*Last Result* - Code that indicates the result of the last run.
The *Status* column has the following status and description information:
*Blank* - The task is not running, or it ran and was successful.
*Running* - The task is currently running.
*Missed* - One or more attempts to run this task was missed.
*Could not start* - The most recent attempt to start the task did not
work.
The *Last Result* column displays a completion code. You can obtain a
full explanation of all Windows completion codes from MSDN, but the
common codes for scheduled tasks are:
*0x0*: The operation completed successfully.
*0x1*: An incorrect function was called or an unknown function was called.
*0xa*: The environment is incorrect.
If the result code has the "C0000XXX" format, the task did not
complete
successfully (the "C" indicates an error condition). The most common
"C"
error code is "0xC000013A: The application terminated as a result of
a
CTRL+C".
Also check the following data in the task's properties:
¿ Make sure the check box that turns on the task has a check
mark.
¿ Check the path to the program and make sure that it is correct.
Also
check the program to see if it requires some command-line parameters
that are missing.
Checking the Scheduled Tasks Log
Scheduled tasks maintains a log file (Schedlgu.txt), in the c:\Windows
folder. You can view the log from the Scheduled Tasks window by clicking
*View Log* on the *Advanced* menu.
The log file size is 32 kilobytes (KB), and when the file reaches its
maximum size, it automatically starts to record new information at the
beginning of the log file and writes over the old log file information.
Checking the Task Scheduler Service
The Task Scheduler service must be running and properly configured to
run tasks. If you had stopped scheduled tasks manually from the
Scheduled Tasks window, the service stops and does not initialize the
next time you start the computer. If the service is not configured to
log on as the local system account, it may not start.
To check the settings for the service:
1. Click *Start*, click *Control Panel*, and then double-click *Administrative
Tools*.
2. Click *Computer Management*.
3. Expand *Services and Applications*, and then click *Services*.
4. Right-click the *Task Scheduler* service, and then click *Properties*.
5. On the *General* tab, make sure that the startup type is set to automatic,
and that the service status is Started. If the service is not running, click
*Start*.
6. On the *Log On* tab, make sure that the local system account is selected,
and that the *Allow service to interact with desktop* check box has a check
mark.
7. Click *OK*, and then quit Computer Management.
------------------------------------------------------------------------
APPLIES TO
Microsoft Windows XP Professional
Microsoft Windows Server 2003, Standard Edition (32-bit x86)
Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)
Microsoft Windows Server 2003, Standard x64 Edition
Microsoft Windows Server 2003, Enterprise x64 Edition
tomado de:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/taskschd/taskschd/time_trigger_example__c___.asp
Task Scheduler
Time Trigger Example (C++)
Note: This documentation is preliminary and is subject to change.
This C++ example shows how to create a task that is scheduled to execute Notepad at a specified time. The task contains a time-based trigger that specifies a start boundary and an end boundary for the task. The task also contains an action that specifies the task to execute Notepad. The task is registered using a password and user name as the security context to run the task. The task also contains idle settings, which specifies how Task Scheduler performs tasks when the computer is in an idle condition.
The following procedure describes how to schedule a task to start an executable at a certain time.
To schedule Notepad to start at a specific time
1. Initialize COM and set general COM security.
2. Create the ITaskService object.
This object allows you to create tasks in a specified folder.
3. Get a task folder to create a task in.
Use the ITaskService::GetFolder method to get the folder, and the ITaskService::NewTask
method to create the ITaskDefinition object.
4. Define information about the task using the ITaskDefinition object, such
as the registration information for the task.
Use the RegistrationInfo property of ITaskDefinition and other properties
of the ITaskDefinition interface to define the task information.
5. Create a time-based trigger using the Triggers property of ITaskDefinition
to access the ITriggerCollection for the task.
Use the ITriggerCollection::Create method (specifying the type of trigger
you want to create) to create a time-based trigger. This allows you to set
the start boundary and the end boundary for the trigger so that the task's
actions will be scheduled to execute at a specified time.
6. Create an action for the task to execute by using the Actions property
of ITaskDefinition to access the IActionCollection interface for the task.
Use the IActionCollection::Create method to specify the type of action that
you want to create. This example uses an IExecAction object, which represents
an action that executes a command-line operation.
7. Register the task using the ITaskFolder::RegisterTaskDefinition method.
The following C++ example shows how to schedule a task to execute Notepad one minute after the task is registered.
/********************************************************************
This sample schedules a task to start notepad.exe 1 minute from the
time the task is registered.
********************************************************************/
#define _WIN32_DCOM
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
#include <wincred.h>
// Include the task header file.
#include <taskschd.h>
# pragma comment(lib, "taskschd.lib")
# pragma comment(lib, "comsupp.lib")
# pragma comment(lib, "credui.lib")
using namespace std;
int __cdecl wmain()
{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
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 );
return 1;
}
// ------------------------------------------------------
// Create a name for the task.
LPCWSTR wszTaskName = L"Time Trigger Test Task";
// Get the windows directory and set the path to notepad.exe.
wstring wstrExecutablePath = _wgetenv( L"WINDIR");
wstrExecutablePath += L"\\SYSTEM32\\NOTEPAD.EXE";
// ------------------------------------------------------
// Securely get the user name and password. The task will
// be created to run with the credentials from the supplied
// user name and password.
CREDUI_INFO cui;
TCHAR pszName[CREDUI_MAX_USERNAME_LENGTH] = "";
TCHAR pszPwd[CREDUI_MAX_PASSWORD_LENGTH] = "";
BOOL fSave;
DWORD dwErr;
cui.cbSize = sizeof(CREDUI_INFO);
cui.hwndParent = NULL;
// Ensure that MessageText and CaptionText identify
// what credentials to use and which application requires them.
cui.pszMessageText = TEXT("Account information for task registration:");
cui.pszCaptionText = TEXT("Enter Account Information for Task Registration");
cui.hbmBanner = NULL;
fSave = FALSE;
// Create the UI asking for the credentials.
dwErr = CredUIPromptForCredentials(
&cui, // CREDUI_INFO structure
TEXT(""), // Target for credentials
NULL, // Reserved
0, // Reason
pszName, // User name
CREDUI_MAX_USERNAME_LENGTH, // Max number for user name
pszPwd, // Password
CREDUI_MAX_PASSWORD_LENGTH, // Max number for password
&fSave, // State of save check box
CREDUI_FLAGS_GENERIC_CREDENTIALS | // Flags
CREDUI_FLAGS_ALWAYS_SHOW_UI |
CREDUI_FLAGS_DO_NOT_PERSIST);
if(dwErr)
{
cout << "Did not get credentials." << endl;
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();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
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();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// ------------------------------------------------------
// Get the pointer to the root task folder. This folder will hold the
// new task that is registered.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder
);
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
pService->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// Check if the same task already exists. If the same task exists, remove
it.
hr = pRootFolder->DeleteTask( _bstr_t( wszTaskName), 0 );
// Create the task builder object to create the task.
ITaskDefinition *pTask = NULL;
hr = pService->NewTask( 0, &pTask );
pService->Release(); // COM clean up. Pointer is no longer used.
if (FAILED(hr))
{
printf("Failed to CoCreate an instance of the TaskService class: %x",
hr);
pRootFolder->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// ------------------------------------------------------
// Get the registration info for setting the identification.
IRegistrationInfo *pRegInfo= NULL;
hr = pTask->get_RegistrationInfo( &pRegInfo );
if( FAILED(hr) )
{
printf("\nCannot get identification pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
hr = pRegInfo->put_Author( _bstr_t( pszName ) );
if( SUCCEEDED(hr) )
hr = pTask->put_RegistrationInfo( pRegInfo );
pRegInfo->Release(); // COM clean up. Pointer is no longer used.
if( FAILED(hr) )
{
printf("\nCannot put identification info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// ------------------------------------------------------
// Create the principal for the task
IPrincipal *pPrincipal = NULL;
hr = pTask->get_Principal( &pPrincipal );
if( FAILED(hr) )
{
printf("\nCannot get principal pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// Set up principal information: register the task with a user name and password
hr = pPrincipal->put_Id( _bstr_t(L"Principal1") );
hr = pPrincipal->put_UserId( _bstr_t(pszName) );
hr = pPrincipal->put_LogonType( TASK_LOGON_PASSWORD );
if( SUCCEEDED(hr) )
hr = pTask->put_Principal( pPrincipal );
pPrincipal->Release(); // COM clean up. Pointer is no longer used.
if( FAILED(hr) )
{
printf("\nCannot put principal info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// ------------------------------------------------------
// Create the settings for the task
ITaskSettings *pSettings = NULL;
hr = pTask->get_Settings( &pSettings );
if( FAILED(hr) )
{
printf("\nCannot get settings pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// Set setting values for the task.
hr = pSettings->put_Enabled(VARIANT_BOOL(true));
hr = pSettings->put_StartWhenAvailable(VARIANT_BOOL(true));
// Set the idle settings for the task.
IIdleSettings *pIdleSettings = NULL;
hr = pSettings->get_IdleSettings( &pIdleSettings );
hr = pIdleSettings->put_WaitTimeout(L"PT5M");
hr = pSettings->put_IdleSettings( pIdleSettings );
if( SUCCEEDED(hr) )
hr = pTask->put_Settings( pSettings );
pSettings->Release(); // COM clean up. Pointer is no longer used.
if( FAILED(hr) )
{
printf("\nCannot put setting info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// ------------------------------------------------------
// Get the trigger collection to insert the time trigger.
ITriggerCollection *pTriggerCollection = NULL;
hr = pTask->get_Triggers( &pTriggerCollection );
if( FAILED(hr) )
{
printf("\nCannot get trigger collection: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// Set the time for the task to start (one minute after the
// code executes).
SYSTEMTIME SysTime;
GetLocalTime( &SysTime );
SysTime.wMinute += 1;
if( SysTime.wMinute > 59 )
SysTime.wHour += 1;
if( SysTime.wHour > 24 )
SysTime.wDay += 1;
WCHAR wTime[MAX_PATH];
swprintf( wTime,
L"%04d-%02d-%02dT%02d:%02d:%02d",
SysTime.wYear,
SysTime.wMonth,
SysTime.wDay,
SysTime.wHour,
SysTime.wMinute,
SysTime.wSecond );
printf("\nSetting StartTime as %S ", wTime );
// Add the time trigger to the task.
ITrigger *pTrigger = NULL;
ITimeTrigger *pTimeTrigger = NULL;
hr = pTriggerCollection->Create( TASK_TRIGGER_TIME, &pTrigger );
if( SUCCEEDED(hr) )
hr = pTrigger->QueryInterface(
IID_ITimeTrigger, (void**) &pTimeTrigger );
if( SUCCEEDED(hr) )
hr = pTimeTrigger->put_Id( _bstr_t( L"Trigger1" ) );
if( SUCCEEDED(hr) )
hr = pTimeTrigger->put_StartBoundary( _bstr_t(wTime) );
if( SUCCEEDED(hr) )
hr = pTimeTrigger->put_EndBoundary( _bstr_t(L"2015-05-02T08:00:00")
);
if( SUCCEEDED(hr) )
hr = pTimeTrigger->put_Enabled( VARIANT_TRUE );
if( SUCCEEDED(hr) )
hr = pTask->put_Triggers( pTriggerCollection );
pTriggerCollection->Release(); // COM clean up. Pointer is no longer
used.
pTrigger->Release();
pTimeTrigger->Release();
if( FAILED(hr) )
{
printf("\nCannot add time trigger to the Task %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// ------------------------------------------------------
// Add an action to the task. This task will execute notepad.exe.
IExecAction *pExecAction = NULL;
IActionCollection *pActionCollection = NULL;
// Get the task action collection pointer.
hr = pTask->get_Actions( &pActionCollection );
if( FAILED(hr) )
{
printf("\nCannot get Task collection pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// Create the action, specifying that it is an executable action.
IAction *pAction = NULL;
hr = pActionCollection->Create( TASK_ACTION_EXEC, &pAction );
// QI for the executable task pointer.
if( SUCCEEDED(hr) )
hr = pAction->QueryInterface(
IID_IExecAction, (void**) &pExecAction );
// Set the path of the executable to notepad.exe.
hr = pExecAction->put_Path( _bstr_t( wstrExecutablePath.c_str() ) );
pActionCollection->Release(); // COM clean up. Pointer is no longer used.
pAction->Release();
pExecAction->Release();
if( FAILED(hr) )
{
printf("\nCannot set path of executable: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
// ------------------------------------------------------
// Save the task in the root folder.
IRegisteredTask *pRegisteredTask = NULL;
hr = pRootFolder->RegisterTaskDefinition(
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE,
_variant_t(_bstr_t(pszName)),
_variant_t(_bstr_t(pszPwd)),
TASK_LOGON_PASSWORD,
_variant_t(L""),
&pRegisteredTask);
if( FAILED(hr) )
{
printf("\nError saving the Task : %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}
printf("\n Success! Task successfully registered. " );
// Clean up.
pRootFolder->Release();
pTask->Release();
pRegisteredTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 0;
}