This project has moved and is read-only. For the latest updates, please go here.

Two Bugs...

Topics: Errors
Aug 17, 2016 at 8:46 PM
Edited Aug 17, 2016 at 9:38 PM
De opgegeven naam is geen juist samengestelde accountnaam.
The name provided is not correct compound account name. (This is a translation from Dutch)

The exception occurred at System.Security.Principal.WindowsIdentity.KerbS4ULogon(String upn, SafeAccessTokenHandle& safeTokenHandle)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName, String type)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName)
at Microsoft.Win32.TaskScheduler.User..ctor(String userName) in C:\Users\dahall\Documents\Visual Studio 2010\Projects\TaskService\User.cs:line 32
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl) in C:\Users\dahall\Documents\Visual Studio 2010\Projects\TaskService\TaskFolder.cs:line 409
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition) in C:\Users\dahall\Documents\Visual Studio 2010\Projects\TaskService\TaskFolder.cs:line 373
and
(14,8):UserId:

The exception occurred at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTaskDefinition(String Path, ITaskDefinition pDefinition, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl)
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl) in C:\Users\dahall\Documents\Visual Studio 2010\Projects\TaskService\TaskFolder.cs:line 430
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition) in C:\Users\dahall\Documents\Visual Studio 2010\Projects\TaskService\TaskFolder.cs:line 373
What triggered this issue was me simply calling RegisterChanges() on an existing task after changing a couple of task settings.
Aug 17, 2016 at 8:53 PM
Edited Aug 17, 2016 at 8:53 PM
For example...
Dim taskServiceObject As New TaskScheduler.TaskService()
Dim taskObject As TaskScheduler.Task = taskServiceObject.GetTask("my task")

If taskObject IsNot Nothing Then
  If taskObject.Definition.Settings.MultipleInstances <> TaskScheduler.TaskInstancesPolicy.Parallel Then
    task.Definition.Settings.MultipleInstances = TaskScheduler.TaskInstancesPolicy.Parallel
    task.RegisterChanges()
    task.Dispose()
  End If
End If

taskServiceObject.Dispose()
Some users reported the above exceptions. I have had to implement a work around for the issue.
Aug 20, 2016 at 4:27 PM
Edited Aug 20, 2016 at 4:30 PM
And another bug...
The exception occurred at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTaskDefinition(String Path, ITaskDefinition pDefinition, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl)
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl) in C:\Users\dahall\Documents\Visual Studio 2010\Projects\TaskService\TaskFolder.cs:line 430
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition) in C:\Users\dahall\Documents\Visual Studio 2010\Projects\TaskService\TaskFolder.cs:line 373
And here's my code...
Dim taskService As New TaskService()
Dim newTask As TaskDefinition = taskService.NewTask
Dim logonTriggerDefinition As LogonTrigger = New LogonTrigger()

If delayed = True Then
  logonTriggerDefinition.Delay = New TimeSpan(0, 0, delayTimeInMinutes, 0, 0)
End If

Dim exePathInfo As New IO.FileInfo(Application.ExecutablePath)
newTask.Actions.Add(New ExecAction(exePathInfo.FullName, "-myargument", exePathInfo.DirectoryName))
exePathInfo = Nothing

newTask.Triggers.Add(logonTriggerDefinition)
newTask.Principal.RunLevel = TaskRunLevel.Highest
newTask.RegistrationInfo.Description = "My Task"
newTask.Principal.LogonType = TaskLogonType.InteractiveToken

With newTask.Settings
  .Compatibility = TaskCompatibility.V2
  .AllowDemandStart = True
  .DisallowStartIfOnBatteries = False
  .RunOnlyIfIdle = False
  .StopIfGoingOnBatteries = False
  .AllowHardTerminate = False
  .ExecutionTimeLimit = Nothing
End With

taskService.RootFolder.RegisterTaskDefinition("My Task", newTask)

newTask.Dispose()
taskService.Dispose()

newTask = Nothing
taskService = Nothing
Coordinator
Aug 20, 2016 at 9:37 PM
What versions of Windows can this run on?
Aug 21, 2016 at 4:09 AM
Edited Aug 21, 2016 at 4:09 AM
Windows 10 is the OS that some of these people are having issues on.
Coordinator
Aug 22, 2016 at 5:01 PM
My guess is that neither one of these are bugs, they expose limitations of the library. ITaskFolder.RegisterTaskDefinition is a picky method in the native library. This wrapper does all it can to provide preventative measures and better errors where possible. The first thing I'd look into is the rights of the user running the library. The exception itself is a better indicator of the problem than the stack.

RegisterChanges has some prerequisites as well. If the task was previously registered with TaskLogonType.InteractiveTokenOrPassword or TaskLogonType.Password, you cannot use the method as you would need to resupply the password.
Aug 22, 2016 at 5:53 PM
Yeah well, I figured out a way around the issue. I just delete the task and recreate it from scratch instead of trying to modify an existing task.