https://msdn.microsoft.com/en-us/library/aa383665(v=VS.85).aspx


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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
' A constant that specifies a time-based trigger.
const TriggerTypeTime = 1
' A constant that specifies an executable action.
const ActionTypeExec = 0   
 
 
'********************************************************
' Create the TaskService object.
Set service = CreateObject("Schedule.Service")
call service.Connect()
 
'********************************************************
' Get a folder to create a task definition in. 
Dim rootFolder
Set rootFolder = service.GetFolder("/")
 
'The taskDefinition variable is the TaskDefinition object.
Dim taskDefinition
' The flags parameter is 0 because it is not supported.
Set taskDefinition = service.NewTask(0
 
'********************************************************
' Define information about the task.
 
' Set the registration info for the task by 
' creating the RegistrationInfo object.
Dim regInfo
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Start notepad at a certain time"
regInfo.Author = "Author Name"
 
'********************************************************
' Set the principal for the task
Dim principal
Set principal = taskDefinition.Principal
 
' Set the logon type to interactive logon
principal.LogonType = 3
 
 
' Set the task setting info for the Task Scheduler by
' creating a TaskSettings object.
Dim settings
Set settings = taskDefinition.Settings
settings.Enabled = True
settings.StartWhenAvailable = True
settings.Hidden = False
 
'********************************************************
' Create a time-based trigger.
Dim triggers
Set triggers = taskDefinition.Triggers
 
Dim trigger
Set trigger = triggers.Create(TriggerTypeTime)
 
' Trigger variables that define when the trigger is active.
Dim startTime, endTime
 
Dim time
time = DateAdd("s"30, Now)  'start time = 30 seconds from now
'startTime = XmlTime("2018-04-03 10:55:00")
 
time = DateAdd("s"35, Now) 'end time = 5 minutes from now
endTime = XmlTime(time)
 
WScript.Echo "startTime :" & startTime
WScript.Echo "endTime :" & endTime
 
trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.ExecutionTimeLimit = "PT5M"    'Five minutes
trigger.Id = "TimeTriggerId"
trigger.Enabled = True
 
'***********************************************************
' Create the action for the task to execute.
 
' Add an action to the task to run notepad.exe.
Dim Action
Set Action = taskDefinition.Actions.Create( ActionTypeExec )
Action.Path = "C:\Windows\System32\notepad.exe"
 
WScript.Echo "Task definition created. About to submit the task..."
 
'***********************************************************
' Register (create) the task.
 
call rootFolder.RegisterTaskDefinition( _
    "Test TimeTrigger", taskDefinition, 6, , , 3)
 
WScript.Echo "Task submitted."
 
 
 
'------------------------------------------------------------------
' Used to get the time for the trigger 
' startBoundary and endBoundary.
' Return the time in the correct format: 
' YYYY-MM-DDTHH:MM:SS. 
'------------------------------------------------------------------
Function XmlTime(t)
    Dim cSecond, cMinute, CHour, cDay, cMonth, cYear
    Dim tTime, tDate
 
    cSecond = "0" & Second(t)
    cMinute = "0" & Minute(t)
    cHour = "0" & Hour(t)
    cDay = "0" & Day(t)
    cMonth = "0" & Month(t)
    cYear = Year(t)
 
    tTime = Right(cHour, 2& ":" & Right(cMinute, 2& _
        ":" & Right(cSecond, 2)
    tDate = cYear & "-" & Right(cMonth, 2& "-" & Right(cDay, 2)
    XmlTime = tDate & "T" & tTime 
End Function
 
cs


'C Lang > VBA,VBS Technic' 카테고리의 다른 글

VBScript Statements  (0) 2018.04.04
VBA에서 Visual Basic .NET으로 코드 변환  (0) 2018.01.31

+ Recent posts