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

Commented 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();
}
}
}
```
Comments: ** Comment from web user: dahall **

I think I have this fixed. Please try out assembly files in attached zip and let me know.


New Post: Creating a remote task in a Workgorup environment.

$
0
0
HI,

I repaired this error going to services.msc and activating the "Remote Registry". But I'm getting another error right now. "Excepción al llamar a "GetFolder" con los argumentos "1": "Sólo se permite esta operación cuando está conectado al servidor. (Excepción de HRESULT: 0x800704E3)""

It's like is trying to get the folder but im not connected and it can't acces.

Someone knows what can i do?

Thanks in advance.

Commented 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();
}
}
}
```
Comments: ** Comment from web user: Crayjin **

I tried it on 64bit Windows 10 Pro Insider Preview Build 10158 and Build 10162 and I still have this exception.

I also did some tests and found out that it crashes only, after the tasks removes itself from the task folder and you want to create the task in that folder again (2nd run). FYI: After the task's removal even an administrator can't remove the task folder.

But if you change the folder, it will work again until the task deletes itself after 40 seconds.

Commented 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();
}
}
}
```
Comments: ** Comment from web user: dahall **

I have run this code with repeated success on Win10 build 10159 and the assemblies I posted here (v2.3.5 beta). Please confirm this works for you.

```
string taskName = "Start", taskFolder = "Test";

TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "some description";
// No need to set td.Principal.LogonType (done in registration)
// No need to set td.Principal.UserId with InteractiveToken
td.Actions.Add("cmd.exe", "-someparameter");

td.Triggers.Add(new RegistrationTrigger { Delay = TimeSpan.FromSeconds(8),
EndBoundary = DateTime.Now + TimeSpan.FromSeconds(20) });

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

// CreateFolder will now create or retrieve the folder with these parameters
TaskFolder testFolder = ts.RootFolder.CreateFolder(taskFolder, null, false);
var t = testFolder.RegisterTaskDefinition(taskName, td,
TaskCreation.CreateOrUpdate, null, null,
TaskLogonType.InteractiveToken);
```

Source code checked in, #96864

$
0
0
* Fixed bugs with setting security on tasks and folders * Fixed bug with exceptions throwing under Win10 for DeleteFolder * Fixed bug with exceptions throwing under Win10 for CreateFolder and made it so existing folder returned if found * Fixed bug in TaskService.GetFolder where it would always work under V1. It also now returns null when not found. * Updates to MMC mockup * Updated version to 2.3.5

New Post: Creating a remote task in a Workgorup environment.

$
0
0
josesi: Thanks for the recommendation. When and how are you getting the GetFolder error? Which method throws the exception, GetFolder explicitly or through another method call? Are you getting a COMException or another exception?

Commented 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();
}
}
}
```
Comments: ** Comment from web user: Crayjin **

Hi dahall,

I only get your code example to work if I don't wait for the created task to delete itself afterwards. If I do, then it throws the exception again (and the task folder cannot be deleted (Got quiet a good amount of test folders in my test machine ;-) )). I don't know if it is a problem on MS side or on your library.

Commented 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();
}
}
}
```
Comments: ** Comment from web user: Crayjin **

Addition: Tested on Preview 10158 and 10162.


Commented 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();
}
}
}
```
Comments: ** Comment from web user: dahall **

I had a thought that this may be caused by holding onto the COM object. Try the following for the last block and let me know your results:
```
using (TaskFolder testFolder = ts.RootFolder.CreateFolder(taskFolder, null, false))
{
testFolder.RegisterTaskDefinition(taskName, td,
TaskCreation.CreateOrUpdate, null, null,
TaskLogonType.InteractiveToken);
td = null;
}
```
Also, you will need to make sure the task's action is not still running when it is trying to delete itself. I have seen one other instance where that caused a problem.

Commented 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();
}
}
}
```
Comments: ** Comment from web user: Crayjin **

Unfortunately it still throws the exception. The task's action is not a problem I think. It opens the "cmd.exe" and I close it every time it spawns.

I will attach my VS project to this post.

New Post: event at just two specific times everyday

$
0
0
Hello,

If I need to schedule an event to occur say at 10h00 and 10h30 everyday, do I add two time triggers without a daily trigger?

Source code checked in, #97064

$
0
0
* Updated to VS 2015 * Changed code to take advantage of C# 6 features

Commented 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();
}
}
}
```
Comments: ** Comment from web user: Crayjin **

Also happens on Windows 10 Pro Insider Preview Build 10240.

Created Unassigned: Error using RegisterTaskDefinition on Windows 7 [12154]

$
0
0
A user of mine is having troubles when scheduling a task from his win2k3 server to a Win7
Everything always works from other servers and for other pc's.

The error he's getting is "The system cannot find the path specified. (Exception from HRESULT: 0x80070003)"
This happens when calling "RegisterTaskDefinition" using the following bit of code:

ts.RootFolder.RegisterTaskDefinition("Rester", tduser, TaskCreation.CreateOrUpdate, Domain + "\\" + User, password, TaskLogonType.Password);



Bit of context(test)
```
Try
{
WindowsImpersonationContext ImpersoToken = Impersonate(User, Domain, password);
if (ImpersoToken != null)
{
using (ImpersoToken)
{
using (TaskService ts = new TaskService(hostname, null, null, null, !IsVistaOrLater))
{
TaskDefinition tduser = ts.NewTask();
bool newVer = (ts.HighestSupportedVersion >= new Version(1, 2));
tduser.Actions.Add(new ExecAction("cmd", "/c set >> " + rootPath + "\\Test.txt", null));
tduser.Settings.DisallowStartIfOnBatteries = false;
tduser.Settings.StopIfGoingOnBatteries = false;

if (newVer)
{
tduser.Principal.RunLevel = TaskRunLevel.Highest; //v2.0
tduser.Settings.AllowDemandStart = true;
}
tduser.RegistrationInfo.Description = "Tester";

try
{
__ ts.RootFolder.RegisterTaskDefinition("Tester", tduser, TaskCreation.CreateOrUpdate, Domain + "\\" + User, password, TaskLogonType.Password);__
ts.GetTask("Tester").Run();
}
catch (Exception ex)
{
//handleException(ex);
}
}
}
RevertToSelf();
}
}
catch (Exception ex)
{
//handleException(ex);
}
```

I'm thinking this might be some obscure folder permissions error.
Any help is greatly appreciated.

Questions ? Please ask!

New Post: "Enable All Tasks History"

$
0
0
It looks like this may only be an issue for Windows Server 2008/2008R2, but the Task History is disabled by default.

Is there an easy way to enable this via Task Scheduler Managed Wrapper?

New Post: System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

$
0
0
I have two servers in a domain: SERVER_A and SERVER_B. SERVER_A runs a collection of scheduled tasks defined in the Task Scheduler.

I have an application that creates scheduled tasks by importing an XML task definition file using the Task Scheduler Managed Wrapper using the following code:

Imports System.IO
Imports Microsoft.Win32.TaskScheduler

Dim ts as TaskService
Dim tf As TaskFolder
Dim FolderName as String = "\TaskFolder"
Dim taskDefFilePath As String
Dim taskDefXML As String

ts = New TaskService("SERVER_A")
tf = ts.GetFolder(FolderName)
taskDefXML = IO.File.ReadAllText(taskDefFilePath)
tf.RegisterTask(
taskName,
taskDefXML,
TaskCreation.CreateOrUpdate,
Nothing,
Nothing,
TaskLogonType.InteractiveToken,
Nothing
)

When the above code is run from SERVER_B (connecting remotely to SERVER_A to set up the scheduled task), the code runs as expected and sets up a new scheduled task. If I run the above code from SERVER_A, then the application throws the following exception:

System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTask(String Path, String XmlText, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl)
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTask(String Path, String XmlText, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl)

I am logging into SERVER_A and SERVER_B using a domain user that has local administrator rights on SERVER_A.

Any idea why I can run the above code remotely from another server in the domain, but get the exception thrown when I try to run locally on SERVER_A?

New Post: "Enable All Tasks History"

$
0
0
Not currently. I know this can be enabled via the Task Scheduler system applet. For years I have intended to figure out what is being done there and add a check into the wrapper, but have never gotten there. If you find a way, please post back for inclusion.

New Post: "Enable All Tasks History"

$
0
0
Your comment inspired me to finally go look at this. I have added the code in the upcoming 2.4 release so that you can use the 'Enabled' property of a TaskEventLog instance to determine if the log is enabled and set it if not.

Source code checked in, #97337

$
0
0
* Update to version 2.4 * Added ability to get and set if task event log is enabled or not (TaskEventLog.Enabled)

New Post: FileNotFoundException during RegisterTaskDefinition?

$
0
0
I have a few people experiencing an issue in my program in which people are reporting a program exception/crash when the program attempts to execute the RegisterTaskDefinition() function.

The following is my code...
Dim taskService As New TaskService

' Where all of my task setup code is. It's too long to mention here so I won't.

taskService.RootFolder.RegisterTaskDefinition("System Restore Checkpoint by System Restore Point Creator", newTask, TaskCreation.CreateOrUpdate, "NT AUTHORITY\System", vbNullString, TaskLogonType.InteractiveToken, vbNullString)
How is the RegisterTaskDefinition() causing an exception on the RootFolder in the Task Scheduler? The RootFolder should always exist so I shouldn't have a problem with this code yet it has some issues on some people's computers. What's going on here?
Viewing all 2206 articles
Browse latest View live


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