TaskScheduler: Unable to connect to Server 2019 to manage tasks
Describe the bug
We have been using this library to manage scheduled tasks and has worked great. Recently with Server 2019 servers getting into the mix, this library can no longer connect.
System.Runtime.InteropServices.COMException (0x80070032): The request is not supported. (Exception from HRESULT: 0x80070032)
at Microsoft.Win32.TaskScheduler.V2Interop.ITaskService.Connect(Object serverName, Object user, Object domain, Object password)
at Microsoft.Win32.TaskScheduler.TaskService.Connect()
at Microsoft.Win32.TaskScheduler.TaskService..ctor(String targetServer, String userName, String accountDomain, String password, Boolean forceV1)
at TaskSchedulerTestApp.Program.Main(String[] args)
To Reproduce Steps to reproduce the behavior:
- Run the following sample console app against a 2019 Server
Expected behavior Should list tasks on the remote server. (Works for 2016 and below but not on 2019)
Environment (please complete the following information):
- Host Windows version (the one running the code): Windows 10
- Library version: 2.8.14
- .Net Framework: 4.7.2
- Remote Windows version (if applicable): Windows Server 2019 Datacenter v10.0 (17763)
Additional context
Here’s the sample app code:
namespace TaskSchedulerTestApp
{
class Program
{
static void Main(string[] args)
{
try
{
var server = "my2019server";
var user = "admin_user";
var domain = "mydomain";
var pass = "secret";
var taskService = new TaskService(server, user, domain, pass);
Debug.Assert(taskService.Connected, "Not connected");
foreach (var task in taskService.AllTasks)
{
Console.WriteLine(task.Name);
}
Console.WriteLine("Done");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.ReadLine();
}
}
}
Do you know if this is a known case? Or is there a different way to do this now?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (9 by maintainers)
Thanks! My issue was the Remote Scheduled Tasks Management firewall rule. Once I enabled that I’m now able to connect. (Somehow Troubleshooting tool also didn’t say anything about this).
So I finally got the server running. I could not use the system tool or the library to connect to the remote WS19 box until I went into the “Allow an app through Windows Firewall” (in Control Panel) and enabled Domain and/or Private access to “Remote Event Log Management” and “Remote Scheduled Tasks Management”.
Once connected however, I did find some incompatibilities when trying to retrieve certain tasks. I’m assuming from past experience that Microsoft has added new undocumented properties to the native COM objects. I will try to get to the bottom of those and will post an update to the library.
However, connecting is not a problem with those two firewall options enabled.
I’m installing WS2019 1903 as we speak. Hopefully I’ll be able to test shortly.