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

Commented Issue: TaskOptionsEditor [12198]

$
0
0
Hi all, is this UI version working at all? I ask before I start getting into the source code and trying to find what may be happening. I just don't get any of the controls filled with the data (I tried the exact same code with TaskEditorDialog instead and it seems to work). Below is the code I'm using.
```
Using TS As New TaskService()
Dim aTaskEditDialog As TaskOptionsEditor
Dim aTaskDef As TaskDefinition = TS.NewTask
aTaskDef.XmlText = tbTaskDef.Text 'this can be blank, but usually have the XML from a TaskDefinition.XML
Dim aTaskOptionsEditor As TaskOptionsEditor = New TaskOptionsEditor(TS, aTaskDef, True, False)
aTaskEditDialog = New TaskOptionsEditor(TS, aTaskDef, True, False)
aTaskEditDialog.TaskFolder = "\" + TScourmanService.TASK_SCHEDULER_FOLDER
aTaskEditDialog.TaskName = PlugInDef.Name 'PlugInDef.Name is a string
'aTaskEditDialog.ReinitializeControls() 'not doing aything
If aTaskEditDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
'aTaskEditDialog always appears empty, not even the task name shows
tbTaskDef.Text = FormatXML(aTaskEditDialog.TaskDefinition.XmlText)
End If
'remove the task we just added - we don't want this task registered in the client machine
TS.GetFolder("\" + TScourmanService.TASK_SCHEDULER_FOLDER).DeleteTask(PlugInDef.Name, False)
End Using
```
Comments: ** Comment from web user: dahall **

Thank you for finding this bug. I have updated the code and have attached a build here. Please test and let me know if this resolves the problem.


Commented Issue: TaskOptionsEditor [12198]

$
0
0
Hi all, is this UI version working at all? I ask before I start getting into the source code and trying to find what may be happening. I just don't get any of the controls filled with the data (I tried the exact same code with TaskEditorDialog instead and it seems to work). Below is the code I'm using.
```
Using TS As New TaskService()
Dim aTaskEditDialog As TaskOptionsEditor
Dim aTaskDef As TaskDefinition = TS.NewTask
aTaskDef.XmlText = tbTaskDef.Text 'this can be blank, but usually have the XML from a TaskDefinition.XML
Dim aTaskOptionsEditor As TaskOptionsEditor = New TaskOptionsEditor(TS, aTaskDef, True, False)
aTaskEditDialog = New TaskOptionsEditor(TS, aTaskDef, True, False)
aTaskEditDialog.TaskFolder = "\" + TScourmanService.TASK_SCHEDULER_FOLDER
aTaskEditDialog.TaskName = PlugInDef.Name 'PlugInDef.Name is a string
'aTaskEditDialog.ReinitializeControls() 'not doing aything
If aTaskEditDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
'aTaskEditDialog always appears empty, not even the task name shows
tbTaskDef.Text = FormatXML(aTaskEditDialog.TaskDefinition.XmlText)
End If
'remove the task we just added - we don't want this task registered in the client machine
TS.GetFolder("\" + TScourmanService.TASK_SCHEDULER_FOLDER).DeleteTask(PlugInDef.Name, False)
End Using
```
Comments: ** Comment from web user: dahall **

More fixes, including the one you mentioned for TaskPropertiesControl, in beta2 attachment.

New Post: Gettings a exception Error (15,8):userId:

$
0
0
What does this error mean?

How do I under VB.net see if a task is created already or not? I've search online but couldn't really find anything that will help.

New Post: Gettings a exception Error (15,8):userId:

$
0
0
That error usually means that the TaskDefinition.Principle.UserId or the userId parameter of the RegisterTaskDefinition has been supplied an invalid user account name.

To answer the second question:
Using TS As New TaskService()
   If TS.FindTask("MyTaskNameHere") = Nothing Then
      ' You don't have that task
   End If
End Using

New Post: Gettings a exception Error (15,8):userId:

$
0
0
Thank you for the reply,

that's weird because it everything was working great until I updated my program and then that happened but It only happened once so far.

New Post: Gettings a exception Error (15,8):userId:

$
0
0
also your code
Using TS As New TaskService()
   If TS.FindTask("MyTaskNameHere") = Nothing Then
      ' You don't have that task
   End If
End Using
the = says its on a declared type in your DLL.

Commented Issue: TaskOptionsEditor [12198]

$
0
0
Hi all, is this UI version working at all? I ask before I start getting into the source code and trying to find what may be happening. I just don't get any of the controls filled with the data (I tried the exact same code with TaskEditorDialog instead and it seems to work). Below is the code I'm using.
```
Using TS As New TaskService()
Dim aTaskEditDialog As TaskOptionsEditor
Dim aTaskDef As TaskDefinition = TS.NewTask
aTaskDef.XmlText = tbTaskDef.Text 'this can be blank, but usually have the XML from a TaskDefinition.XML
Dim aTaskOptionsEditor As TaskOptionsEditor = New TaskOptionsEditor(TS, aTaskDef, True, False)
aTaskEditDialog = New TaskOptionsEditor(TS, aTaskDef, True, False)
aTaskEditDialog.TaskFolder = "\" + TScourmanService.TASK_SCHEDULER_FOLDER
aTaskEditDialog.TaskName = PlugInDef.Name 'PlugInDef.Name is a string
'aTaskEditDialog.ReinitializeControls() 'not doing aything
If aTaskEditDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
'aTaskEditDialog always appears empty, not even the task name shows
tbTaskDef.Text = FormatXML(aTaskEditDialog.TaskDefinition.XmlText)
End If
'remove the task we just added - we don't want this task registered in the client machine
TS.GetFolder("\" + TScourmanService.TASK_SCHEDULER_FOLDER).DeleteTask(PlugInDef.Name, False)
End Using
```
Comments: ** Comment from web user: MarcoAGarciaR **

Hi Dahall, I'm not sure why, but I cannot test the code you send. If I replace the files with the corresponding ones you sent, I still get the same behavior. I found what seems to be another issue, this time using the TaskEditorDialog. In the checkbox "If the task is not scheduled to run again, delete it after:" is you set the time to, for example, 1 second or 30 minutes, it'll not update the task definition accordingly! This one is sort of s show stopper for me.

Commented Issue: TaskOptionsEditor [12198]

$
0
0
Hi all, is this UI version working at all? I ask before I start getting into the source code and trying to find what may be happening. I just don't get any of the controls filled with the data (I tried the exact same code with TaskEditorDialog instead and it seems to work). Below is the code I'm using.
```
Using TS As New TaskService()
Dim aTaskEditDialog As TaskOptionsEditor
Dim aTaskDef As TaskDefinition = TS.NewTask
aTaskDef.XmlText = tbTaskDef.Text 'this can be blank, but usually have the XML from a TaskDefinition.XML
Dim aTaskOptionsEditor As TaskOptionsEditor = New TaskOptionsEditor(TS, aTaskDef, True, False)
aTaskEditDialog = New TaskOptionsEditor(TS, aTaskDef, True, False)
aTaskEditDialog.TaskFolder = "\" + TScourmanService.TASK_SCHEDULER_FOLDER
aTaskEditDialog.TaskName = PlugInDef.Name 'PlugInDef.Name is a string
'aTaskEditDialog.ReinitializeControls() 'not doing aything
If aTaskEditDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
'aTaskEditDialog always appears empty, not even the task name shows
tbTaskDef.Text = FormatXML(aTaskEditDialog.TaskDefinition.XmlText)
End If
'remove the task we just added - we don't want this task registered in the client machine
TS.GetFolder("\" + TScourmanService.TASK_SCHEDULER_FOLDER).DeleteTask(PlugInDef.Name, False)
End Using
```
Comments: ** Comment from web user: dahall **

I the code I posted, I have checked that error with a number of values and find that it retains the value each time. Please clean build your code, do not reference the NuGet package, and instead directly reference the assemblies I provided.


Source code checked in, #97737

$
0
0
* Fixed bug in TaskSettings.DeleteExpiredTaskAfter to allow for both a 'not set' value (TimeSpan.Zero) and an 'immediate' value (TimeSpan.FromSeconds(1)). * Fixed multiple problems in TaskPropertiesControl: - Automatic maintenance deadline and period validation - Update to work with fix to Settings.DeleteExpiredTaskAfter - Enabling problem with restart interval - Exception when setting task priority - Validating URI * Fixed similar problems in TaskOptionsEditor * Fixed intialization problem in Runtime tab of TaskOptionsEditor

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: everrr **

hi guys, i have met the same issue on my win10 entreprise.
the scenario is as below:
1: use local account to register a task 'task a' under root folder
2: use admin account to delete 'task a', then register a new 'task a' (with the same task name) under root folder.

the admin account could delete the task a without any issue, but get failed while trying to register task a again, the exception and error message are the same as the top of this thread. i am wondering whether it is a lib issue or come from win10? i have this doubt since this never happned on win7 or win8.

do we have a feasible solution to this yet? if not, I am going to try native API which I really don't want to :(

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 now verified this happens across all Win10 builds and product versions and I have tested it with the library and C++ code calling the native COM library directly with the same results. This is a Microsoft bug. I have submitted it but have not received a reply.

New Post: Gettings a exception Error (15,8):userId:

$
0
0
Try with Null as in the changed example

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 **

__everrr__: In your steps, you said you "use local account" or "use admin account". Does that mean you are connecting to the TaskService using those accounts, running the executable under those accounts, or registering the task with those account's credentials?

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 **

__everrr__: Is there a possibility that the system presenting the problem was upgraded from a Windows 10 Technical Preview build?

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: everrr **

i agree its a microsoft issue, but i just figured out a workaround to avoid this issue.

basically, as you discussed previously, the issue will only happen after the task remove itself and re create the task again in the same folder. so we could prevent the task from removing itself, to do that just set a long EndBoundary.

```
TimeTrigger timeTrigger = new TimeTrigger();
timeTrigger.StartBoundary = DateTime.Now + TimeSpan.FromSeconds(2);
timeTrigger.EndBoundary = DateTime.Now + TimeSpan.FromSeconds(1000);
```
and after the task get registered successfully, then delete the task
```
using (TaskService ts = new TaskService())
{
if (TaskExist(ReminderTaskName, ts)) {

ts.RootFolder.DeleteTask(ReminderTaskName, false);
_logger.LogError(ReminderTaskName + " task deleted --------------------");
}
}
```
and then ,next when we re create the task again, it works properly.


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: everrr **

when I say "use admin account", it just mean "Run as administrator"

i installed the win10 enterprise directly, not by an upgrade

Created Unassigned: RegisterChanges fails on XP [12208]

$
0
0
In V1 mode, the RegisterChanges fails saying the following:

```
Microsoft.Win32.TaskScheduler.NotV1SupportedException: Folder other than the root (\) was requested on a system only supporting Task Scheduler 1.0.
à Microsoft.Win32.TaskScheduler.TaskService.GetFolder(String folderName)
à Microsoft.Win32.TaskScheduler.Task.RegisterChanges()

```

The task was created using the RootFolder property.

As a workaround I had to write this:
```
task.Folder.RegisterTaskDefinition(task.Name, task.Definition);

```

However a fix would be better :)

Created Unassigned: Make exceptions serializable [12209]

$
0
0
Currently, exceptions (such as NotV1SupportedException) are not serializable, and thus, do not cross appdomains, remoting, etc.
It would be great to have them serializable.

New Post: Moving to github?

$
0
0
(this is not a troll!)
Moving to a more open repository would allow third-party developpers (such as me) to submit patches, and help improving the product.
On codeplex, this is a bit more difficult.

Edited Issue: RegisterChanges() fails on XP [12208]

$
0
0
In V1 mode, the RegisterChanges fails saying the following:

```
Microsoft.Win32.TaskScheduler.NotV1SupportedException: Folder other than the root (\) was requested on a system only supporting Task Scheduler 1.0.
à Microsoft.Win32.TaskScheduler.TaskService.GetFolder(String folderName)
à Microsoft.Win32.TaskScheduler.Task.RegisterChanges()

```

The task was created using the RootFolder property.

As a workaround I had to write this:
```
task.Folder.RegisterTaskDefinition(task.Name, task.Definition);

```

However a fix would be better :)
Comments: ** Comment from web user: dahall **

Before your call to RegisterChanges, what is the string value of task.Path? This will help me determine if I missed a condition on the path before assuming it wasn't the root folder.

Viewing all 2206 articles
Browse latest View live


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