dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.2k stars 191 forks source link

Task Does not Create on French OS Computer to English Computer #979

Closed paulwetter closed 3 months ago

paulwetter commented 9 months ago

Describe the bug Using this library to create a task from powershell or C# on a French OS results in the following error. This error message is generated from powershell and is slightly different in C#:

Exception lors de l'appel de « RegisterTaskDefinition » avec « 2 » argument(s) : « (16,8):UserId: »
Au caractère Ligne:1 : 1

English translation:

Exception when calling 'RegisterTaskDefinition' with '2' argument(s): '(16,8):UserId:'
To the character Line:1: 1

To Reproduce Steps to reproduce the behavior in Powershell:

add-type -Path "Microsoft.Win32.TaskScheduler.dll"
$ts = [Microsoft.Win32.TaskScheduler.TaskService]::new("\\MyPC")
$td = $ts.NewTask()
$td.Principal.UserId = "SYSTEM"
$td.Principal
$td.Principal.LogonType = "ServiceAccount"
$trigger = [Microsoft.Win32.TaskScheduler.TimeTrigger]::new()
$td.Triggers.Add($trigger)
$trigger.StartBoundary = get-date 2024/01/24
$act = [Microsoft.Win32.TaskScheduler.ExecAction]::new()
$act.Path = "C:\windows\system32\CMD.exe"
$td.Actions.Add($act)
$ts.RootFolder.RegisterTaskDefinition("Test_Task", $td)

Expected behavior I expect "Test_Task" to be created on MyPC. but get the error instead.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

paulwetter commented 9 months ago

Resolution or at least a workaround may come in the form of creating the task from the XML:

$ts.RootFolder.RegisterTask(taskName, $td.XmlText)

Doing further testing to confirm.

dahall commented 3 months ago

Please reopen if you need further help.