I found this sample script here (http://msdn.microsoft.com/en-us/
library/aa446818(VS.85).aspx)
It works great as written, However, If I change the logon name to
something other than "Local Service"
If fails at line 88. The error is (null): (44,4):Task:
I have tried it several ways, but it seems to be the User Name and
Password it does not like.
I am changing "Local Service" to "domain\user" and the 5th paramiter
to "password".
Here is the script as found at Microsoft:
'---------------------------------------------------------
' This sample schedules a task to start notepad.exe 30 seconds after
' the system is booted.
'---------------------------------------------------------
' A constant that specifies a boot trigger.
const TriggerTypeBoot = 8
' A constant that specifies an executable action.
const ActionTypeExecutable = 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 = "Task will execute Notepad when " & _
"the computer is booted."
regInfo.Author = "Author Name"
' Set the task setting info for the Task Scheduler by
' creating a TaskSettings object.
Dim settings
Set settings = taskDefinition.Settings
settings.StartWhenAvailable = True
'********************************************************
' Create a boot trigger.
Dim triggers
Set triggers = taskDefinition.Triggers
Dim trigger
Set trigger = triggers.Create(TriggerTypeBoot)
' Trigger variables that define when the trigger is active.
Dim startTime, endTime
startTime = "2006-05-02T10:49:02"
endTime = "2006-05-02T10:52:02"
WScript.Echo "startTime :" & startTime
WScript.Echo "endTime :" & endTime
trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.ExecutionTimeLimit = "PT5M" ' Five minutes
trigger.Id = "BootTriggerId"
trigger.Delay = "PT30S" ' 30 Seconds
'***********************************************************
' Create the action for the task to execute.
' Add an action to the task. The action executes notepad.
Dim Action
Set Action = taskDefinition.Actions.Create( ActionTypeExecutable )
Action.Path = "C:\Windows\System32\notepad.exe"
WScript.Echo "Task definition created. About to submit the task..."
'***********************************************************
' Register (create) the task.
const createOrUpdateTask = 6
call rootFolder.RegisterTaskDefinition( _ '<------ Error occours
here!
"Test Boot Trigger", taskDefinition, createOrUpdateTask, _
"Local Service", , 5)
WScript.Echo "Task submitted."
I don't have an answer to your specific question but if this was my problem
then I would try to create a scheduled task with the command schtasks.exe
(WinXP only). It comes with a detailed help file that shows you what you can
do and how to do it. After solving your problem with schtasks.exe, you can
probably apply the solution to your script.
I found the answer. You can't use 5 and a user name and password.
Also, to get the script to run with elevated privleges, you need to
set the RunLevel to 1;
Here is one that works:
'<------- Begin Script --------------------------->
Const TASK_TRIGGER_DAILY = 2
Const TASK_ACTION_EXEC = 0
Const TASK_CREATE = 2
Const TASK_Trigger_Boot = 8
Const TASK_RUNLEVEL_HIGHEST = 1
Dim strUser, strPassword
strUser = "domain\svc-account"
strPassword = "Password"
Set objService = CreateObject("Schedule.Service")
objService.Connect()
Set objFolder = objService.GetFolder("\")
Set objTaskDefinition = objService.NewTask(0)
Dim principal
Set principal = objTaskDefinition.Principal
' Set the logon type to TASK_LOGON_PASSWORD
principal.LogonType = 1
' Tasks will be run with the highest privileges.
principal.RunLevel = TASK_RUNLEVEL_HIGHEST
Set colTasks = objTaskDefinition.Triggers
Set objTrigger = colTasks.Create(TASK_Trigger_Boot)
objTrigger.StartBoundary = "2009-05-27T08:00:00-00:00"
objTrigger.ExecutionTimeLimit = "PT5M" 'Five minutes
Set colActions = objTaskDefinition.Actions
Set objAction = colActions.Create(TASK_ACTION_EXEC)
objAction.ID = "Boot Task Test"
objAction.Path = "cscript.exe"
objAction.WorkingDirectory = "c:\scripts"
objAction.Arguments = "/nologo c:\scripts\chkBL.vbs"
Set objInfo = objTaskDefinition.RegistrationInfo
objInfo.Author = "Mike Felkins"
objInfo.Description = "Test task that displays BitLocker status every
boot."
Set objSettings = objTaskDefinition.Settings
objSettings.Enabled = True
objSettings.Hidden = False
objSettings.StartWhenAvailable = True
objFolder.RegisterTaskDefinition "Test Boot Trigger",
objTaskDefinition, TASK_CREATE, strUser, strPassword, 1
'<------- End Script --------------------------->
You can find more info at http://msdn.microsoft.com/en-us/library/aa383607(VS.85).aspx