![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Scripting Task Scheduler Hi, 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." |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Scripting Task Scheduler "OldDog" <mikef2691@xxxxxx> wrote in message news:377c9ccd-3fc8-4838-bdb2-d0415500d001@xxxxxx Quote: > Hi, > > 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." 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. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Scripting Task Scheduler On May 28, 12:50*pm, "Pegasus [MVP]" <n...@xxxxxx> wrote: Quote: > "OldDog" <mikef2...@xxxxxx> wrote in message > > news:377c9ccd-3fc8-4838-bdb2-d0415500d001@xxxxxx > > > > > Quote: > > Hi, Quote: > > I found this sample script here (http://msdn.microsoft.com/en-us/ > > library/aa446818(VS.85).aspx) Quote: > > 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: Quote: > > I have tried it several ways, but it seems to be the User Name and > > Password it does not like. Quote: > > I am changing *"Local Service" to "domain\user" and the 5th paramiter > > to "password". Quote: > > Here is the script as found at Microsoft: Quote: > > '--------------------------------------------------------- > > ' This sample schedules a task to start notepad.exe 30 seconds after > > ' the system is booted. > > '--------------------------------------------------------- Quote: > > ' A constant that specifies a boot trigger. > > const TriggerTypeBoot = 8 > > ' A constant that specifies an executable action. > > const ActionTypeExecutable = 0 Quote: > > '******************************************************** > > ' Create the TaskService object. > > Set service = CreateObject("Schedule.Service") > > call service.Connect() Quote: > > '******************************************************** > > ' Get a folder to create a task definition in. > > Dim rootFolder > > Set rootFolder = service.GetFolder("\") Quote: > > ' The taskDefinition variable is the TaskDefinition object. > > Dim taskDefinition > > ' The flags parameter is 0 because it is not supported. > > Set taskDefinition = service.NewTask(0) Quote: > > '******************************************************** > > ' Define information about the task. Quote: > > ' 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" Quote: > > ' Set the task setting info for the Task Scheduler by > > ' creating a TaskSettings object. > > Dim settings > > Set settings = taskDefinition.Settings > > settings.StartWhenAvailable = True Quote: > > '******************************************************** > > ' Create a boot trigger. > > Dim triggers > > Set triggers = taskDefinition.Triggers Quote: > > Dim trigger > > Set trigger = triggers.Create(TriggerTypeBoot) Quote: > > ' Trigger variables that define when the trigger is active. > > Dim startTime, endTime > > startTime = "2006-05-02T10:49:02" > > endTime = "2006-05-02T10:52:02" Quote: > > WScript.Echo "startTime :" & startTime > > WScript.Echo "endTime :" & endTime Quote: > > trigger.StartBoundary = startTime > > trigger.EndBoundary = endTime > > trigger.ExecutionTimeLimit = "PT5M" * *' Five minutes > > trigger.Id = "BootTriggerId" > > trigger.Delay = "PT30S" * * * * * * * *' 30 Seconds Quote: > > '*********************************************************** > > ' Create the action for the task to execute. Quote: > > ' 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" Quote: > > WScript.Echo "Task definition created. About to submit the task..." Quote: > > '*********************************************************** > > ' Register (create) the task. > > const createOrUpdateTask = 6 > > call rootFolder.RegisterTaskDefinition( _ * * *'<------ Error occours > > here! > > * *"Test Boot Trigger", taskDefinition, createOrUpdateTask, _ > > * *"Local Service", , 5) Quote: > > 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.- Hide quoted text - > > - Show quoted text - 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/libr...07(VS.85).aspx |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Task Scheduler Compatibility module task status update failed | General Discussion | |||
| Task Scheduler Error-task image corrupt or has been tampered with User_Feed_Synchroni | General Discussion | |||
| Task Scheduler: Create task to open webpage? | Vista General | |||
| Schedule a task with Vista task Scheduler wakes up computer and mo | Vista General | |||
| Task scheduler returns an error : the task image is corrupt ortamp | Vista performance & maintenance | |||