ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Windows Scheduler functions
  • Overview
  • ScheduledTask structure
  • Example
  • Example for adding a task
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
The ScheduledTask structure is used to define the characteristics of a scheduled task. The variables of this structure are reinitialized by SchedulerReset.
Remark: When creating a new task, the ScheduledTask structure is used as well as the TriggerScheduledTask structure.
ScheduledTask structure
The different variables of ScheduledTask structure are as follows:
ScheduledTask.ApplicationCharacter string.
Name and path of program to run.
ScheduledTask.StopOnIdleEndBoolean.
True if the task must be stopped as soon as the system resumes an activity.
This variable is set to False by default.
ScheduledTask.StopOnBatteriesBoolean.
True if the task must be stopped when the computer switches to battery power.
This variable is set to True by default.
ScheduledTask.ErrorCodeInteger.
Last error code returned by the task (0 if the task was successfully completed or if the program has never been started).
This variable is read-only and is updated with SchedulerTaskProperties.
ScheduledTask.CommentCharacter string.
Comment associated with the task. This comment will be visible in the task properties. This comment can be multilingual.
ScheduledTask.IdleWaitTimeoutInteger in minutes.
Timeout during which the system will wait for an idle time before performing the task.
If ScheduledTask.IdleTimeout is not set to 0, this variable is used to specify the amount of time required before the system cancels the task execution.
This variable is set to 60 minutes by default.
ScheduledTask.IdleTimeoutInteger in minutes.
Amount of system idle time required before performing the task. The task will be performed only if the system is inactive.
Example: An antivirus scan is performed every day at 1:00 PM if the system is inactive since 30 minutes.
This variable is set to 0 (immediate timeout) by default.
ScheduledTask.LastRunDateDateTime.
Date of last task execution.
This variable is read-only and is updated with SchedulerTaskProperties.
ScheduledTask.MaxRunTimeDuration.
Maximum task duration. Amount of time required before the system ends the task.
If this variable is set to 0, the task will be run as long as necessary.
This variable is set to 72 hours by default.
Remark: This variable can correspond to:
  • an integer corresponding to the number of hundredths of a second,
  • a Duration variable,
  • the direct indication of duration (1 h for example).
ScheduledTask.SystemOnBoolean.
  • True if the computer must be woken up to perform this task (the system must not be in sleep mode),
  • False otherwise.
This variable is set to False by default.
ScheduledTask.RunIfLoggedOnBoolean.
  • True if the task must be performed only when an interactive session (with user identification) is started on the computer of user identified by ScheduledTask.User,
  • False otherwise.
This feature allows you not to specify the user password (however, the username must be specified).
This variable is set to False by default: the task will be run even if the session is ended.
Remark: This variable requires Windows XP or later (does not operate in Windows 2000).
ScheduledTask.CommandLineCharacter string.
Parameters to pass in command line to the application that will be run.
ScheduledTask.PasswordCharacter string.
User password. This user was specified in ScheduledTask.User. Used to perform a scheduled task according to a user account.
If this password is modified, this modification will also apply to all the tasks linked to this user.
ScheduledTask.TriggerCountInteger.
Number of task schedules (which means number of events that will trigger the task).
This variable is read-only and is updated with SchedulerTaskProperties.
ScheduledTask.DontRunIfOnBatteriesBoolean.
True if the task must be stopped when the computer switches to battery power.
This variable is set to True by default.
ScheduledTask.NextRunTimeDateTime.
Date of next scheduled task execution.
This variable is read-only and is updated with SchedulerTaskProperties.
ScheduledTask.WorkingDirectoryCharacter string.
Working directory of the application to run (empty string if the working directory corresponds to the scheduler directory (MSTASK.EXE)).
Caution: If this directory is not specified, it corresponds to the directory of ScheduledTask.Application.
ScheduledTask.DeleteWhenDoneBoolean.
True if the task must be deleted automatically when there is no more possible conditions for running it (the end date of each occurrence has been reached for example).
This variable is set to False by default.
ScheduledTask.UserCharacter string.
Name of user whose account is used to perform the task.
Remark: if you are using a domain, this domain must be specified.
Example

Example for adding a task

SchedulerReset()
// Create the scheduled task
ScheduledTask.Application = "MyExecutable.exe"
ScheduledTask.CommandLine = QryAllAboutBackup.Name
ScheduledTask.SystemOn = True
ScheduledTask.Comment = "WINDEV program"
 
// Create the schedules for the scheduled task
// nBackupType is a radio button proposing a backup
// single, weekly or monthly backup...
 
TriggerScheduledTask.Type = nBackupType
 
// Execution date of the single backup
IF nBackupType = schedDaily THEN
IF EDT_SingleDate <> "" THEN
IF EDT_SingleTime <> "" THEN
TriggerScheduledTask.Date = EDT_SingleDate
TriggerScheduledTask.Time = EDT_SingleTime
ELSE
Info("Enter a valid backup time.")
RETURN
END
ELSE
Info("Enter a valid backup date.")
RETURN
END
END
// Monthly backup
IF nBackupType = schedMonthly THEN
IF EDT_SingleTime <> "" THEN
TriggerScheduledTask.Day = RADIO_DayOfMonth
TriggerScheduledTask.Time = EDT_SingleTime
ELSE
Info("Enter a valid backup time.")
RETURN
END
END
// Weekly backup
IF nBackupType = schedWeekly THEN
IF EDT_SingleTime <> "" THEN
TriggerScheduledTask.DayOfWeek = RADIO_DayOfWeek
TriggerScheduledTask.Time = EDT_SingleTime
ELSE
Info("Enter a valid backup time.")
RETURN
END
END
IF NOT SchedulerAddTask("MyTask") THEN
Error(ErrorInfo())
ELSE
Info("The application was added to the task manager of Windows")
END
Minimum version required
  • Version 10
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 08/26/2022

Send a report | Local help