1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package tschexec
import (
"encoding/xml"
)
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tsch/0d6383e4-de92-43e7-b0bb-a60cfa36379f
type taskTimeTrigger struct {
XMLName xml.Name `xml:"TimeTrigger"`
StartBoundary string `xml:"StartBoundary,omitempty"` // Derived from time.Time
EndBoundary string `xml:"EndBoundary,omitempty"` // Derived from time.Time; must be > StartBoundary
Enabled bool `xml:"Enabled"`
}
type idleSettings struct {
StopOnIdleEnd bool `xml:"StopOnIdleEnd"`
RestartOnIdle bool `xml:"RestartOnIdle"`
}
type settings struct {
XMLName xml.Name `xml:"Settings"`
Enabled bool `xml:"Enabled"`
Hidden bool `xml:"Hidden"`
DisallowStartIfOnBatteries bool `xml:"DisallowStartIfOnBatteries"`
StopIfGoingOnBatteries bool `xml:"StopIfGoingOnBatteries"`
AllowHardTerminate bool `xml:"AllowHardTerminate"`
RunOnlyIfNetworkAvailable bool `xml:"RunOnlyIfNetworkAvailable"`
AllowStartOnDemand bool `xml:"AllowStartOnDemand"`
WakeToRun bool `xml:"WakeToRun"`
RunOnlyIfIdle bool `xml:"RunOnlyIfIdle"`
StartWhenAvailable bool `xml:"StartWhenAvailable"`
Priority int `xml:"Priority,omitempty"` // 1 to 10 inclusive
MultipleInstancesPolicy string `xml:"MultipleInstancesPolicy,omitempty"`
ExecutionTimeLimit string `xml:"ExecutionTimeLimit,omitempty"`
DeleteExpiredTaskAfter string `xml:"DeleteExpiredTaskAfter,omitempty"` // Derived from time.Duration
IdleSettings idleSettings `xml:"IdleSettings,omitempty"`
}
type actionExec struct {
XMLName xml.Name `xml:"Exec"`
Command string `xml:"Command"`
Arguments string `xml:"Arguments"`
}
type actions struct {
XMLName xml.Name `xml:"Actions"`
Context string `xml:"Context,attr"`
Exec []actionExec `xml:"Exec,omitempty"`
}
type principals struct {
XMLName xml.Name `xml:"Principals"`
Principals []principal `xml:"Principal"`
}
type principal struct {
XMLName xml.Name `xml:"Principal"`
ID string `xml:"id,attr"`
UserID string `xml:"UserId"`
RunLevel string `xml:"RunLevel"`
}
type task struct {
XMLName xml.Name `xml:"Task"`
TaskVersion string `xml:"version,attr"`
TaskNamespace string `xml:"xmlns,attr"`
TimeTriggers []taskTimeTrigger `xml:"Triggers>TimeTrigger,omitempty"`
Actions actions `xml:"Actions"`
Principals principals `xml:"Principals"`
Settings settings `xml:"Settings"`
}
var (
defaultSettings = settings{
MultipleInstancesPolicy: "IgnoreNew",
DisallowStartIfOnBatteries: false,
StopIfGoingOnBatteries: false,
AllowHardTerminate: true,
RunOnlyIfNetworkAvailable: false,
IdleSettings: idleSettings{
StopOnIdleEnd: true,
RestartOnIdle: false,
},
AllowStartOnDemand: true,
Enabled: true,
Hidden: true,
RunOnlyIfIdle: false,
WakeToRun: false,
Priority: 7, // 7 is a pretty standard value for scheduled tasks
StartWhenAvailable: true,
}
defaultPrincipals = principals{
Principals: []principal{
{
ID: "SYSTEM",
UserID: "S-1-5-18",
RunLevel: "HighestAvailable",
},
},
}
)
|