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

Created Unassigned: Error using RegisterTaskDefinition on Window10 Professional [12169]

$
0
0
______Error using RegisterTaskDefinition on Window10 Proffessional______

When calling "RegisterTaskDefinition", the error I am getting is:

the task xml contains a value which is incorrectly formatted or out of range
Exception from HResult:0x80041318

Any help is appreciated.

New Post: FileNotFoundException during RegisterTaskDefinition?

$
0
0
First of all, SYSTEM cannot be the user when InteractiveToken is used since SYSTEM cannot run interactively. Please check the documentation on this site to see how to correctly call RegisterTaskDefinition using the SYSTEM account.

If, after making that change, you still experience the error, please let me know which OS versions are running and the status of the account connecting to the TaskService (admin, user, etc.).

Commented Unassigned: Error using RegisterTaskDefinition on Window10 Professional [12169]

$
0
0
______Error using RegisterTaskDefinition on Window10 Proffessional______

When calling "RegisterTaskDefinition", the error I am getting is:

the task xml contains a value which is incorrectly formatted or out of range
Exception from HResult:0x80041318

Any help is appreciated.
Comments: ** Comment from web user: dahall **

Without information regarding the settings, triggers, and actions you have added to the TaskDefinition, I am unable to troubleshoot your issue. Please also ensure that the account running your code has sufficient permissions to create a task. I will also need to know the OS on which you're running the code and how you are instantiating the TaskService instance.

Commented Unassigned: Error using RegisterTaskDefinition on Window10 Professional [12169]

$
0
0
______Error using RegisterTaskDefinition on Window10 Proffessional______

When calling "RegisterTaskDefinition", the error I am getting is:

the task xml contains a value which is incorrectly formatted or out of range
Exception from HResult:0x80041318

Any help is appreciated.
Comments: ** Comment from web user: shilpa0812 **

Thanks for looking into the issue. I am getting the error while running the code on Windows 10 professional only. On other windows versions it is working correctly. The code is as following:

public void CreateSchedulerTask()
{
try
{
using (TaskService taskService = new TaskService())
{

bool IsNewer = taskService.HighestSupportedVersion > new Version(1, 2);
//Retrieve Assembly Path
string pathForExe = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Program.exe");

//Delete taks if exists
taskService.RootFolder.DeleteTask("SomeTask", false);

// Create a new task definition and assign properties
TaskDefinition taskDefinition = taskService.NewTask();

//Security
taskDefinition.Principal.LogonType = TaskLogonType.InteractiveToken;
taskDefinition.Principal.UserId = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

//This property not supported in XP
if (IsNewer)
{
taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
}

taskDefinition.RegistrationInfo.Description = "Keeps your software up to date. If this task is disabled or stopped, your software will not be kept up to date, meaning security vulnerabilities that may arise cannot be fixed and features may not work. This task uninstalls itself when there is no software using it.";

// Add a trigger that, starting every month
// and Saturday and repeat every 10 minutes for the following 11 hours
MonthlyTrigger monthlyTrigger = new MonthlyTrigger();
monthlyTrigger.EndBoundary = DateTime.Now.AddYears(10);
taskDefinition.Triggers.Add(monthlyTrigger);

// Create an action that will launch Notepad whenever the trigger fires
taskDefinition.Actions.Add(new ExecAction(pathForExe));

// Register the task in the root folder
taskService.RootFolder.RegisterTaskDefinition("SomeTask", taskDefinition);
}
}
catch (Exception ex)
{
logger.Error(ex);
ServiceHelper.LogError(ex);
}
}

New Post: FileNotFoundException during RegisterTaskDefinition?

$
0
0
So something like this instead?
taskService.RootFolder.RegisterTaskDefinition("System Restore Checkpoint by System Restore Point Creator", newTask, TaskCreation.CreateOrUpdate, "NT AUTHORITY\System")

New Post: FileNotFoundException during RegisterTaskDefinition?

Source code checked in, #97491

$
0
0
* Fixed TaskEventLog.Enabled setter * Added TaskService.GetEventLog method

Source code checked in, #97492

$
0
0
* Added script tool to test harness

Source code checked in, #97500

New Post: Trying to disable a task (vb)

$
0
0
Hi, I create a task using the following code...


Try
        Dim ts As New TaskService()

        ' Create a new task definition and assign properties
        Dim td As TaskDefinition = ts.NewTask()
        td.RegistrationInfo.Description = "Does something"
        td.Principal.RunLevel = TaskRunLevel.Highest
        td.Principal.LogonType = TaskLogonType.InteractiveToken

        ' Create a trigger that will fire the task at 06:00 every day.
        Dim dt As New DailyTrigger(1)
        dt.StartBoundary = CDate(DateAdd(DateInterval.Day, 1, Now()).ToString("dd/MM/yyyy 06:00:00"))
        td.Triggers.Add(dt)

        'create a trigger that will fire the task every thursday at 04:00.
        Dim wt As WeeklyTrigger = DirectCast(td.Triggers.Add(New WeeklyTrigger()), WeeklyTrigger)
        wt.StartBoundary = CDate(DateAdd(DateInterval.Day, 1, Now()).ToString("dd/MM/yyyy 04:00:00"))
        wt.DaysOfWeek = DaysOfTheWeek.Thursday

        ' Create an action that will launch Notepad whenever the trigger fires
        td.Actions.Add(New ExecAction("notepad.exe", "c:\test.txt", Nothing))

        ' Register the task in the root folder
        ts.RootFolder.RegisterTaskDefinition("TestTask", td)

    Catch ex As Exception
        MsgBox("error - " & ex.Message)
    End Try

...and I'm trying to disable it using the following
    Try
        Dim ts As New TaskService

        Dim t As Task = ts.GetTask("TestTask")
        t.Enabled = False
        t.RegisterChanges()
    Catch ex As Exception
        MsgBox("error - " & ex.Message)
    End Try

...but when I use the code to disable it, the code runs OK, but the task isn't disabled.

What am I missing?

PS - the code to define the triggers looks a bit messy as I'm still getting my head around this - sorry.

New Post: Trying to disable a task (vb)

$
0
0
See this answer for detail on the Enabled property: https://taskscheduler.codeplex.com/discussions/585279

For your code, there are some shortcuts in VB that will make your code easier to read:
Dim ts As New TaskService()

' Create a new task definition and assign properties
Dim td As TaskDefinition = ts.NewTask()
td.RegistrationInfo.Description = "Does something"
td.Principal.RunLevel = TaskRunLevel.Highest
td.Principal.LogonType = TaskLogonType.InteractiveToken

' Create a trigger that will fire the task at 06:00 every day.
td.Triggers.Add(New DailyTrigger(1) With {.StartBoundary = DateTime.Today.AddHours(6) })

' Create a trigger that will fire the task every Thursday at 04:00.
td.Triggers.Add(New WeeklyTrigger With {.StartBoundary = DateTime.Today.AddHours(4), .DaysOfWeek = DaysOfTheWeek.Thursday })

' Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add("notepad.exe", "c:\test.txt")

' Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition("TestTask", td)

New Post: Trying to disable a task (vb)

$
0
0
Thanks for the tidier code. And I'm sure I tried that method to disable the task, but it's working now, so thank you!

New Post: Trying to disable a task (vb)

$
0
0
Update - It work on tasks that I've created.

When I try to disable a task created by someone else, and the machine name has subsequently changed, I can't disable the task.

The code throws an exception - "No mapping between account names and security IDs was done (Exception from HRESULT 0x80070534)"

Also, if I try to disable the task by right-clicking it in task scheduler, it won't let me, displaying an error message saying 'The specified account name is not valid'. In order to fix this, I have to go into the properties of the task and change the user account.

Strangely, the task with the incorrect account name still runs, so how would I change the account name so that I can disable it?

New Post: Trying to disable a task (vb)

$
0
0
I believe you just need to create an instance of the existing task and the re-register the task using new credentials. The samples page shows how to get a current task instance. You will need to supply the new user information in the RegisterTaskDefinition method.

Released: Release 2.4.0 (Aug 14, 2015)

$
0
0
Some bug fixes, better support for Windows 8 additions to core library, addition of Fluent syntax, and crontab syntax, since the 1.9.4 release. 2.4.0 release includes a number of bug fixes for Windows 10. Since 2.0.3 release, added support for .NET 2.0, 3.5 and 4.0, security handling, version compatibility handling (for connecting to up or down-stream versions), bug fixes, enhancements to history control and event trigger editor, compensation for deprecated email and message actions on Win8, and improved performance and marshalling. See Source Code for full details of changes. In 2.3.0, a more modern editor has been added as TaskOptionsEditor.

Download Descriptions
  • TaskScheduler.zip - Includes the base library (Microsoft.Win32.TaskScheduler.dll) with no UI code. Works with .NET 2.0 and higher. Separate assemblies for .NET 2.0, 3.5 and 4.0. Add this assembly as a reference to interact with Task Scheduler on all systems with IE4 and later. This package is also available via NuGet with package name TaskScheduler.
  • TaskSchedulerEditor.zip - Includes the UI library (Microsoft.Win32.TaskSchedulerEditor.dll) with all supporting assemblies. Works with .NET 2.0 and higher. Separate assemblies for .NET 2.0, 3.5 and 4.0. Add this assembly as a reference along with Microsoft.Win32.TaskScheduler.dll to get editor controls and dialogs that allow for viewing and editing tasks, triggers, actions, lists, etc. This package is also available viaNuGet with package nameTaskSchedulerEditor.
  • TaskSchedulerHelp.zip - Includes the Microsoft Help compatible help files for both the base and editor libraries. Extract all files and then run Install_TaskScheduler.bat to integrate the help.

Updated Release: Release 2.4.0 (Aug 14, 2015)

$
0
0
Some bug fixes, better support for Windows 8 additions to core library, addition of Fluent syntax, and crontab syntax, since the 1.9.4 release. 2.4.0 release includes a number of bug fixes for Windows 10. Since 2.0.3 release, added support for .NET 2.0, 3.5 and 4.0, security handling, version compatibility handling (for connecting to up or down-stream versions), bug fixes, enhancements to history control and event trigger editor, compensation for deprecated email and message actions on Win8, and improved performance and marshalling. See Source Code for full details of changes. In 2.3.0, a more modern editor has been added as TaskOptionsEditor.

Download Descriptions
  • TaskScheduler.zip - Includes the base library (Microsoft.Win32.TaskScheduler.dll) with no UI code. Works with .NET 2.0 and higher. Separate assemblies for .NET 2.0, 3.5 and 4.0. Add this assembly as a reference to interact with Task Scheduler on all systems with IE4 and later. This package is also available via NuGet with package name TaskScheduler.
  • TaskSchedulerEditor.zip - Includes the UI library (Microsoft.Win32.TaskSchedulerEditor.dll) with all supporting assemblies. Works with .NET 2.0 and higher. Separate assemblies for .NET 2.0, 3.5 and 4.0. Add this assembly as a reference along with Microsoft.Win32.TaskScheduler.dll to get editor controls and dialogs that allow for viewing and editing tasks, triggers, actions, lists, etc. This package is also available via NuGet with package name TaskSchedulerEditor.
  • TaskSchedulerHelp.zip - Includes the Microsoft Help compatible help files for both the base and editor libraries. Extract all files and then run Install_TaskScheduler.bat to integrate the help.

New Post: Trying to disable a task (vb)

$
0
0
OK,

That's what I thought, but it's not working for me, so here's the code I'm trying, could you tell me what I'm doing wrong please?
    'ask for the task name
    Dim Taskname As String = InputBox("What's the task name?")
    Dim td As TaskDefinition = Nothing

    Try
        'see if the username is set to something.
        Dim ts As New TaskService
        Dim thetask As Task = ts.GetTask(Taskname)
        Dim Authorname As String = "NotGood"
        Try
            td = thetask.Definition
            Authorname = td.RegistrationInfo.Author.ToString
        Catch ex As Exception
            Authorname = "NotGood"
        End Try

        'if we get a name, then this task was created by the 'wrong' user - try creating the task again to change the author.
        If Authorname <> "NotGood" Then
            td.Principal.RunLevel = TaskRunLevel.Highest
            td.Principal.LogonType = TaskLogonType.InteractiveToken
            td.RegistrationInfo.Author = "tevalis"
            thetask.RegisterChanges()
            ts.RootFolder.RegisterTaskDefinition(Taskname, td)
        End If

    Catch ex As Exception
        MsgBox("Error - " & ex.Message)
    End Try

New Post: Is that permission issue, then how do I fix this?

$
0
0
Hello,
  1. Created a task (Let's say this is TaskA)
    When running the task..user account : SYSTEM
    Set Run with highest privileges.
    Set Action to run a console exe application (Let's say this is ConsoleApp) at the specific time.
In that ConsoleApp, what it does is to add one more trigger based on some business logic..and call RegisterChanges to update...

Here are what I noticed..
  1. When running the ConsoleApp with admin right in command window, it works file.
  2. When running the ConsoleApp without admin right, it didn't work. (GetTask method returns null, so no update happened)
  3. When running the ConsoleApp under context of Windows Task Scheduler(Under Actions tab), it throws exception, System.IO.FileNotFoundException
I think this is a security related issue... I CANNOT change the SYSTEM account to some other account for the TaskA. Is there any way that ConsoleApp should be run under the context of Windows Task Scheduler to make update happen?

Thanks,

Created Unassigned: Error creating TaskDefinition on Window10 Home [12187]

$
0
0
When I try to create the TaskDefinition and see the XMlText of a System Task(SQM data sender)
'tk.Definition.XmlText' threw an exception of type __'System.OutOfMemoryException'__ exception.

exception base: "Insufficient memory to continue the execution of the program"

StackTrace:
at Microsoft.Win32.TaskScheduler.V2Interop.ITaskDefinition.get_XmlText()
at Microsoft.Win32.TaskScheduler.TaskDefinition.get_XmlText()

Code:
// Get the service on the local machine
TaskService ts = new TaskService(targetServer, userName, accountDomain, password);

__Note:__ The wrapper successfully created the Task Definitions of some 70 odd system tasks before failing at this one.
TaskName: SQM data sender

Thanks in advance
Any help will be appreciated

Commented Unassigned: Error creating TaskDefinition on Window10 Home [12187]

$
0
0
When I try to create the TaskDefinition and see the XMlText of a System Task(SQM data sender)
'tk.Definition.XmlText' threw an exception of type __'System.OutOfMemoryException'__ exception.

exception base: "Insufficient memory to continue the execution of the program"

StackTrace:
at Microsoft.Win32.TaskScheduler.V2Interop.ITaskDefinition.get_XmlText()
at Microsoft.Win32.TaskScheduler.TaskDefinition.get_XmlText()

Code:
// Get the service on the local machine
TaskService ts = new TaskService(targetServer, userName, accountDomain, password);

__Note:__ The wrapper successfully created the Task Definitions of some 70 odd system tasks before failing at this one.
TaskName: SQM data sender

I am using the latest version of the wrapper.

Thanks in advance
Any help will be appreciated
Comments: ** Comment from web user: dahall **

This error is thrown by the base Microsoft library. I can try to help, but I may not be able to do anything. If you will send the code used to create the task definition, I may be able to spot the items that could be causing the problem.

Viewing all 2206 articles
Browse latest View live


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