Using the Notepad example on the Codeplex web site, I am trying to figure out how to create a new task and specify the Windows Domain, Username, and Password to be used when the Task is Executed (ie: The value defined in the 'Run As' box of a Task's Properties.
I am writing my code in Microsoft Visual Basic .NET 2010.
Below is my code:
Dim ts As New TaskService
Dim td As TaskDefinition
td = ts.NewTask
td.RegistrationInfoDescription = "Test"
td.Actions.Add(New ExeAction("notepad.exe", "c:\test.txt"))
ts.RootFolder.RegisterTaskDefinition("Test", td, TaskCreation.Create, "domain\userid", "password")
If I leave off the last three parameters of the 'RegiserTaskDefinition' call, it creates the task and defaults the 'Run As' Property of the task as 'NT AUTHORITY\SYSTEM', but this task will not run unless I change the 'Run As' property value to
a valid Windows domain and userid, and then click on the Password Button to define the Password.
If I add the last three parameters, I get a message that this is not supported in the 1.0 version of the task scheduler. I am using the 1.0 version, because my laptop is running on Windows XP, so my question would be: Is there a way to specify the domain\userid
and password when creating a task (programatically), with the 1.0 version of the Microsoft Task Scheduler installed?