Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

Closed Issue: System.IO.FileNotFoundException when registering task under 64 bit Windows 10 Pro Insider Preview Build 10158 [12142]

$
0
0
At the moment I'm running into this problem on 64 bit Windows 10 Pro Insider Preview Build 10158. Same call works on 64 bit Windows 8.1 Pro.

System.IO.FileNotFoundException, The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
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)

Used .NET-Framework 2.0 - Version 2.3.4.0

In fact I'm using the TaskCreation.CreateOrUpdate enum value and the process is elevated. Let me give you some more information:

I'm using a RegistrationTrigger, with a delay of 8 seconds and a EndBoundary of 20 seconds.
* RunLevel is TaskRunLevel.LUA
* DeleteExpiredTaskAfter is 40 seconds
* Principal.UserId is the UserName of the Win32_ComputerSystem ManagementObject (Example: WIN-GVLEGB4ESV6\Test )

```
using System;
using Microsoft.Win32.TaskScheduler;
using System.Management;

namespace TestTaskScheduler
{
class Program
{
static void Main(string[] args)
{

var ts = new TaskService();

TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "some description";
td.Principal.LogonType = TaskLogonType.InteractiveToken;

var computerSystemClass = new ManagementClass("Win32_ComputerSystem");
var computerSystems = computerSystemClass.GetInstances();
var enumerator = computerSystems.GetEnumerator();
while (enumerator.MoveNext())
{
var computerSystem = enumerator.Current;
td.Principal.UserId = (string)computerSystem["UserName"];
}

td.Actions.Add(new ExecAction("cmd.exe", "-someparameter"));

// Create Trigger
var trigger = new RegistrationTrigger { Enabled = true };
trigger.Delay = TimeSpan.FromSeconds(8);
trigger.EndBoundary = DateTime.Now + TimeSpan.FromSeconds(20);
td.Triggers.Add(trigger);

TaskFolder tf = ts.RootFolder;

td.Principal.RunLevel = TaskRunLevel.LUA;

td.Settings.StartWhenAvailable = true;
td.Settings.Hidden = false;
td.Settings.MultipleInstances = TaskInstancesPolicy.StopExisting;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.IdleSettings.StopOnIdleEnd = false;
td.Settings.DeleteExpiredTaskAfter = TimeSpan.FromSeconds(40);

TaskFolder testFolder = null;

foreach (TaskFolder taskFolder in tf.SubFolders)
{
if (taskFolder.Name.Equals("TEST", StringComparison.OrdinalIgnoreCase))
{
testFolder = taskFolder;
}
}

if (testFolder == null)
testFolder = tf.CreateFolder("TEST");

testFolder.RegisterTaskDefinition("Start", td, TaskCreation.CreateOrUpdate, null, null, TaskLogonType.InteractiveToken);
Console.ReadKey();
}
}
}
```

Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>