Adding any task to Automatic Maintenance

JohnOfE

Member
Member
Messages
107
Location
West Auckland
This is half FYI and half Question:

I found out how to add a task to the Automatic Maintenance that runs each morning. I use Geekzone's EPG collector to fill in the guide on Media Centre and I though it would be nice for it to run as part of Automatic Maintenance rather than wake the computer up again later to do it's thing.

Here's how:

Create an XML files in notepad and paste this in...

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2013-02-01T19:34:03.9529687</Date>
<Author>johnofe-laptop\JohnOfE</Author>
<Description>EPG Loader</Description>
</RegistrationInfo>
<Triggers />
<Principals>
<Principal id="LocalSystem">
<UserId>JOHNOFE-LAPTOP\JohnOfE</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<MaintenanceSettings>
<Period>P1DT0H</Period>
<Deadline>P7DT0H</Deadline>
<Exclusive>false</Exclusive>
</MaintenanceSettings>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="LocalSystem">
<Exec>
<Command>C:\Program Files (x86)\Geekzone\EPG Collector\EPGCollector.exe</Command>
</Exec>
</Actions>
</Task>

Save the file then in Task Scheduler, import the XML and it will appear. Edit it from there further if you want.

I got this from exporting a task that runs as part of Automatic Maintenance and edited it to suit.

the thing is, I still don't know how it works! I have't been able to create a schedules task from scratch that runs as part of Automatic Maintenance.

Other than plagiarising existing tasks to get what I want, does anyone know how it's really done?

I have what I want, and it works great being able to run all the things I want all at the same time at 3AM each day, as part of Windows' ritual. Even better, if I disable it from waking the computer, everything runs when I'm logged in and Idle. It's fantastic.

Any suggestions or something I missed?
 

My Computer

System One

  • OS
    Windows 8 Pro Pack x64
    System Manufacturer/Model
    JohnOfE Special
    Other Info
    Too many systems and combinations!
I was hoping someone else would answer you as I’m not a programmer, but I’m guessing it’s done by coding/editing the XML in a text editor, then importing it into Task Scheduler (which is what you’re doing anyway). Here’s what the Developer Network says:


Creating an Automatic Maintenance task:
This section details how developers can create a task using a task definition in XML or C language. Keep in mind that maintenance activity should not launch any user interface that requires user interaction, as Automatic Maintenance is completely silent and runs when the user is not present. Indeed, if the user interacts with the computer during Automatic Maintenance, any tasks in process will be ended until the next idle period. More info in below link.

Automatic Maintenance (Windows)


Defining an Automatic Maintenance Task:
You can convert any Task Scheduler task to a maintenance task. To do so, you must confirm that your application can be suspended. Then, you must extend the task definition with the new MaintenanceSettings and AllowStartOnDemand elements.

The main concern with creating a maintenance task is ensuring that the system can suspend and restart the task. The system will likely suspend a maintenance task multiple times; therefore, you need to ensure that your application is able to save its own state, and then resume at an arbitrary time. This ensures that the system does not perform the same part of your task repeatedly. More info in below link.

Automatic Maintenance (Preliminary)


MaintenanceSettings Definition:
Period
Specifies how often the task needs to be started during Automatic Maintenance.

Deadline
Specifies the amount of time after which the Task scheduler attempts to run the task during emergency Automatic Maintenance, if the task failed to complete during regular Automatic Maintenance.

Exclusive
Indicates whether the Task scheduler must start the task during the Automatic Maintenance in exclusive mode.

MaintenanceSettings (maintenanceSettingsType) Element (Windows)


Period Format:
Specifies how often the task needs to be started during Automatic maintenance.

The format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of days, T is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the number of seconds (for example, "PT5M" specifies 5 minutes and "P1M4DT2H5M" specifies one month, four days, two hours, and five minutes). The minimum value is one minute.

Period Element (Windows)
 

My Computer

System One

  • OS
    Win 8 64-bit
Further to this topic, I have read into this more and discovered that it's not quite suitable in some cases. Microsoft recommends that ANY task that runs as part of Automatic Maintenance must be capable or pausing or stopping unexpectedly, which my Epg task is not. My Epg task may constantly stop and restart over and over and may never actually finish, which is not good.

A task may be set as exclusive, which means that it will run last and on it's own, but will risk not running at all if the computer ceases to be idle until. It will run once it approaches it's deadline time however.

So: use wisely.
 

My Computer

System One

  • OS
    Windows 8 Pro Pack x64
    System Manufacturer/Model
    JohnOfE Special
    Other Info
    Too many systems and combinations!
Back
Top