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

New Post: Add task from xml string

$
0
0
What is my mistake ?
  using (TaskService ts = new TaskService())
              {
                  string Task_Settings = System.IO.File.ReadAllText(@"D:\DailyTrigger.xml");

                  TaskFolder tf = ts.RootFolder;
                  tf.RegisterTask(@"XMLTask", Task_Settings);
              }  
My xml file works successfully with method NewTaskFromFile.

New Post: Add task from xml string

$
0
0
NewTaskFromFile will give you a TaskDefinition but does not create (register) the task. The problem you may be having is a permissions problem when registering. Are you running the executable from an account that has permissions to create tasks? Are you not running as Administrator and having UAC block your access? Your code is correct if you have permissions. Alternately, you could do all that in one line:
TaskService.Instance.RootFolder.ImportTask("XMLTask", @"D:\DailyTrigger.xml");
If you have permission problems, you may need to supply user information:
using (var ts = new TaskService())
{
   // If user information is in the XML file under the Principal tag, you can use this short form:
   ts.RootFolder.RegisterTaskDefinition("XMLTask", ts.NewTaskFromFile(@"D:\DailyTrigger.xml"));
   // If you need to supply user information at this time use this form. See documentation for detail on TaskLogonType.
   ts.RootFolder.RegisterTaskDefinition("XMLTask", ts.NewTaskFromFile(@"D:\DailyTrigger.xml"),
      TaskCreation.CreateOrUpdate, "username", "password", TaskLogonType.XYZ);
}

Source code checked in, #95425

$
0
0
* Spelling corrections to comments and help text

Closed Unassigned: Release 2.3.1 bug with .NET 3.5 [12088]

$
0
0
Hello,

I am testing the release 2.3.1 over the previous 2.0.3 with .NET 3.5. I took the 2.0 version of the dll and I have compilation errors.
Some types from System.Core v3.5.0.0 have the same names as types in Microsoft.Win32.TaskScheduler.dll:
System.Diagnostics.Eventing.Reader.PathType
System.Diagnostics.Eventing.Reader.EventRecord

I am getting:
The type 'System.Diagnostics.Eventing.Reader.PathType' exists in both
'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\64cd053d\cb6b2d6d\assembly\dl3\2fe9cd28\002ef9be_1064d001\Microsoft.Win32.TaskScheduler.DLL'
and 'c:\WINDOWS\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll'

Can you rename those or do a .NET 3.5 special version?

Thanks
Comments: This is corrected and the 2.3.2 release will include a build for .NET 3.5 that will also be included in the NuGet package.

Source code checked in, #95427

$
0
0
* Fixed problem when including TaskScheduler.dll in a .NET 3.5 project. Updated conditional build parameters around system event code, changed project to include a 3.5 specific build, and update NuGet packager with additional library.

Source code checked in, #95431

$
0
0
* Added .NET 3.5 build support to editor

Commented Issue: Release 2.3.1 bug with .NET 3.5 [12088]

$
0
0
Hello,

I am testing the release 2.3.1 over the previous 2.0.3 with .NET 3.5. I took the 2.0 version of the dll and I have compilation errors.
Some types from System.Core v3.5.0.0 have the same names as types in Microsoft.Win32.TaskScheduler.dll:
System.Diagnostics.Eventing.Reader.PathType
System.Diagnostics.Eventing.Reader.EventRecord

I am getting:
The type 'System.Diagnostics.Eventing.Reader.PathType' exists in both
'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\64cd053d\cb6b2d6d\assembly\dl3\2fe9cd28\002ef9be_1064d001\Microsoft.Win32.TaskScheduler.DLL'
and 'c:\WINDOWS\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll'

Can you rename those or do a .NET 3.5 special version?

Thanks
Comments: ** Comment from web user: PMartrenchar **

Great :)
Thanks

Source code checked in, #95482


Updated Release: Release 2.3.2 (Apr 24, 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. 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 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 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.

Released: Release 2.3.2 (Apr 24, 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. 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. SeeSource 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.3.2 (Apr 24, 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. 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: Using 'RunOnluIfLoggedOn' is not working for me

$
0
0
The above is not working and i am catching this

Task Scheduler 2.0 (1.2) does not support setting this property. You must use an InteractiveToken in order to have the task run in the current user session.

Thanks in advance

New Post: How to enable a task in task scheduler using C#?

$
0
0
Hi, All

I also have problems with task edition. Shortly:
  1. "RegisterChanges" is not needed in case we want only to change "Enabled". Moreover in case it will be called - "Enabled" flag will be returned to previous state. Don't know why this happens.
  2. In my case task contains only single action to start exe file. What I want to do is to modify path to exe file. Here it is reworked piece of code:
using (var ts = new TaskService())
{
    var alreadyPresentTask = ts.FindTask(settings.TaskSchedulerTaskName);
    foreach (var action in alreadyPresentTask.Definition.Actions)
    {
        if (action is ExecAction)
        {
            var execAction = action as ExecAction;
            if (null != execAction)
            {
                var root = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var newPath = System.IO.Path.Combine(root, Path.GetFileName(execAction.Path));

                string oldPath = execAction.Path;
                execAction.Path = newPath;

                string oldWorkingDirectory = execAction.WorkingDirectory;
                execAction.WorkingDirectory = root;
            }
        }
    }
    alreadyPresentTask.RegisterChanges();
    alreadyPresentTask.Enabled = true;
}
As You can see "RegisterChanges" here called before modification of Enabled flag, because in opposite case task wouldn't be enabled. But main problem is what this code works in "windows 8" but work partially in "windows xp": Modified only "Enabled" flag properly, but paths remains unchanged. Without any exceptions, errors etc... Simply do nothing. Can someone help me?

New Post: Using 'RunOnluIfLoggedOn' is not working for me

$
0
0
Yes, when using TaskScheduler 2.0 (Vista and later) the RunOnlyIfLoggedOn property will throw an exception. You must instead do as instructed and register the task using an InteractiveToken setting.

New Post: How to enable a task in task scheduler using C#?

$
0
0
You can set alreadyPresentTask.Definition.Settings.Enabled = true before calling RegisterChanges. This will ensure the task is enabled and you do not have to set the alreadyPresentTask.Enabled property.

Also, FindTask is a bit of a risky method in that it is non-deterministic. It will return the first task in any folder it finds whose name matches the one provided to the method. You are much safer to use the GetTask method and provide the full path to the task as it is deterministic. Also, either your if (action is ExecAction) or your if (null == execAction) statement is unnecessary as they both check the same condition.

I believe the problem is related to how C# handles references and potentially the wrapper not accommodating that well. To resolve, I would try something like:
// 1. If using the local instance of the Task Scheduler, you can use the static Instance property.
// 2. Prepend the exact folder name in GetTask.
var alreadyPresentTask = TaskService.Instance.GetTask("\\" + settings.TaskSchedulerTaskName);
if (alreadyPresentTask != null)
{
  // 3. Avoid re-registering the task if not needed.
  bool changed = false;
  for (int i = 0; i < alreadyPresentTask.Definition.Actions.Count; i++)
  {
    ExecAction execAction = alreadyPresentTask.Definition.Actions[i] as ExecAction;
    if (execAction != null)
    {
      var root = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
      var newPath = System.IO.Path.Combine(root, Path.GetFileName(execAction.Path));

      // 4. I believe that by creating a new action and replacing the old you
      //    will avoid the reference problem.
      alreadyPresentTask.Definition.Actions[i] = new ExecAction(newPath, execAction.Arguments, root);

      changed = true;
    }
  }
  if (changed)
  {
    // 5. Using this setting will ensure the task stays enabled
    alreadyPresentTask.Definition.Settings.Enabled = true;
    alreadyPresentTask.RegisterChanges();
  }
}

New Post: How to enable a task in task scheduler using C#?

New Post: cannot creating a task without running app as admin

$
0
0
when trying to create tasks I get access denied unless the program is stated as admin. the user is a local admin on the system, the task is being created on the same system, and the task is to be run as a different user. below is the gist of the code, please let me know
using (TaskService ts = new TaskService())
{
           TimeTrigger start = new TimeTrigger { StartBoundary = dateTime1.Value };
            TaskDefinition td = ts.NewTask();
            td.Triggers.Add(start);
            td.Principal.RunLevel = TaskRunLevel.Highest;
            td.Settings.Compatibility = TaskCompatibility.V2_2;
            td.Actions.Add(new ExecAction(Environment.GetCommandLineArgs()[0], cmd, null));
            ts.RootFolder.RegisterTaskDefinition("Task Name", td, TaskCreation.Create, username, password, TaskLogonType.Password);
}
any ideas?

New Post: Task Sheduler Sinlge page web application

$
0
0
I created console application that call asmx web services. For example we give it a name "CallWebService".
Now, I am creating single page web application for create, read, update, and delete tasks. I use Ext JS. When user create task, user choose(with checkboxes) web methods. Web Methods with parameters stored in ms sql database. For task action we set "CallWebService" path. For arguments of action i will write methods id. When task start, "CallWebService" will take arguments(method's id), then get method's parameters(web service url, namespace etc) and call specefic web methods.
My questions :
1) How i can set task settings programmatically like :
wTrigger.DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Friday;
mTrigger.DaysOfMonth = new int[] { 3, 6, 10, 18 };
if i can get only string variables(string Friday = "Friday") from CRUD web application ?

2) How can i get all task parameters and save it to
List<Dictionary<string, object>> result = new List<Dictionary<string, object>>() ?
This way i will display it in user intarface.

Source code checked in, #95781

New Post: cannot creating a task without running app as admin

$
0
0
The code calling the TaskService constructor must be running as Administrator to avoid UAC blocks. The security rights of the TaskService instance will determine if the RegisterTaskDefinition method can be called. Registering a task as a specific user instruct that task to run as that user.
Viewing all 2206 articles
Browse latest View live


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