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.22k stars 192 forks source link

Bad Example for Task.RunEx Method #818

Closed bulldogamd closed 5 years ago

bulldogamd commented 5 years ago

This example doesn't even work

var runningTask = tsk.RunEx(TaskRunFlags.IgnoreConstraints, "DOMAIN\User", "info");

The second parm is expecting an integer.

Help Topic: https://dahall.github.io/TaskScheduler/html/M_Microsoft_Win32_TaskScheduler_Task_RunEx.htm

dahall commented 5 years ago

You're right. I forgot to put the 0 value in for the second param. I'll correct.

bulldogamd commented 5 years ago

Thanks!

Have you gotten RunEx to actually work on a remote device? I've been using Run successfully but on certain devices Task Scheduler gets in the Queued Status when you attempt to Run. Known issue with Task Scheduler.

So i attempt to run this and it does NOT start

using (TaskService ts = new TaskService(ComputerName, creds.UserName, creds.Domain, creds.Password, forceV1))

RunningTask runtask = tsk.RunEx(TaskRunFlags.IgnoreConstraints, 0, "Domain\User");

This doesn't start either

RunningTask runtask = tsk.RunEx(0, 0, "Domain\User");

However I can get it to run by running SCHTASKS where /RUN /I is ignoring constraints.

Thanks for your support.

dahall commented 5 years ago

I just connected to a remote Windows Server 2019 using

new TaskService("ServerName", "user", "DOMAIN", "pwd", false);

then successfully ran

var task = ts.AddTask("Test", QuickTriggerType.Daily, "notepad.exe", "$(Arg0)", "DOMAIN\\user", "pwd", TaskLogonType.InteractiveToken, null);
task.RunEx(TaskRunFlags.IgnoreConstraints, 0, null, @"C:\cmd.txt");

My guess is that you have a permissions problem on the remote computer. Please see the Wiki on security for what you may need to allow (firewall settings, account security and running services) on the remote computer.

dahall commented 5 years ago

Have you been able to resolve your issue by adjusting the configuration of the connected systems?