I have two servers in a domain: SERVER_A and SERVER_B. SERVER_A runs a collection of scheduled tasks defined in the Task Scheduler.
I have an application that creates scheduled tasks by importing an XML task definition file using the Task Scheduler Managed Wrapper using the following code:
Imports System.IO
Imports Microsoft.Win32.TaskScheduler
Dim ts as TaskService
Dim tf As TaskFolder
Dim FolderName as String = "\TaskFolder"
Dim taskDefFilePath As String
Dim taskDefXML As String
ts = New TaskService("SERVER_A")
tf = ts.GetFolder(FolderName)
taskDefXML = IO.File.ReadAllText(taskDefFilePath)
tf.RegisterTask(
taskName,
taskDefXML,
TaskCreation.CreateOrUpdate,
Nothing,
Nothing,
TaskLogonType.InteractiveToken,
Nothing
)
When the above code is run from SERVER_B (connecting remotely to SERVER_A to set up the scheduled task), the code runs as expected and sets up a new scheduled task. If I run the above code from SERVER_A, then the application throws the following exception:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTask(String Path, String XmlText, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl)
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTask(String Path, String XmlText, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl)
I am logging into SERVER_A and SERVER_B using a domain user that has local administrator rights on SERVER_A.
Any idea why I can run the above code remotely from another server in the domain, but get the exception thrown when I try to run locally on SERVER_A?
I have an application that creates scheduled tasks by importing an XML task definition file using the Task Scheduler Managed Wrapper using the following code:
Imports System.IO
Imports Microsoft.Win32.TaskScheduler
Dim ts as TaskService
Dim tf As TaskFolder
Dim FolderName as String = "\TaskFolder"
Dim taskDefFilePath As String
Dim taskDefXML As String
ts = New TaskService("SERVER_A")
tf = ts.GetFolder(FolderName)
taskDefXML = IO.File.ReadAllText(taskDefFilePath)
tf.RegisterTask(
taskName,
taskDefXML,
TaskCreation.CreateOrUpdate,
Nothing,
Nothing,
TaskLogonType.InteractiveToken,
Nothing
)
When the above code is run from SERVER_B (connecting remotely to SERVER_A to set up the scheduled task), the code runs as expected and sets up a new scheduled task. If I run the above code from SERVER_A, then the application throws the following exception:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTask(String Path, String XmlText, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl)
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTask(String Path, String XmlText, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl)
I am logging into SERVER_A and SERVER_B using a domain user that has local administrator rights on SERVER_A.
Any idea why I can run the above code remotely from another server in the domain, but get the exception thrown when I try to run locally on SERVER_A?