This project has moved. For the latest updates, please go here.

Action Samples

All actions are derived from the abstract Action class. All versions of the base library support the ExecAction. It only has three properties that allow it to run an executable with parameters.

ExecAction ea1 = new ExecAction("notepad.exe", "file.txt", null);
ExecAction ea2 = new ExecAction();
ea2.Path = "notepad.exe";
ea.Arguments = "file2.txt";

Cross-platform Support

Post Vista, in the V2 library, there are three new actions. Under V1 systems (XP/WS2003 and earlier), these actions can be enabled via PowerShell and setting the TaskDefinition.Actions.PowerShellConversion property to PowerShellActionPlatformOption.All. Turning on support for PowerShell under V1 systems also allow the library to support more than one action.

TaskDefinition td = TaskService.Instance.NewTask()
td.Actions.PowerShellConversion = PowerShellActionPlatformOption.All;
// Define rest of task and register...

This same property can be used to prevent PowerShell from being used to convert EmailAction and ShowMessageAction actions under Windows 8 and newer systems:

TaskDefinition td = TaskService.Instance.NewTask()
td.Actions.PowerShellConversion = PowerShellActionPlatformOption.Never;
// Define rest of task and register...

Email, Message and COM Object Actions

The EmailAction allows for an email to be sent when the task is triggered. It works as follows:

EmailAction eAction = new EmailAction("Task fired", "sender@email.com", "recipient@email.com", "You just got a message", "smtp.company.com");
eAction.Cc = "alternate@email.com";

You can also display a message when the trigger fires using the ShowMessageAction.

ShowMessageAction msg = new ShowMessageAction("You just got a message!", "SURPRISE");

The last action is the most complex. It allows the task to execute and In-Proc COM server object that implements the ITaskHandler interface. There is a sample project that shows how to do this in the Downloads section, but here is how to define the action.

ComHandlerAction comAction = new ComHandlerAction(new Guid("{CE7D4428-8A77-4c5d-8A13-5CAB5D1EC734}"));
comAction.Data = "Something specific the COM object needs to execute. This can be left unassigned as well.";

Last edited Nov 11, 2015 at 5:54 PM by dahall, version 3

Comments

dahall Oct 16 at 10:33 PM 
@AliceDev: There is no mechanism to do exactly as you've written, that is calling a VB method directly from a task. However, you can have a task call a ComHandlerAction this is hosted by a VB COM object. For an example in C# (sorry, no template or code for VB), see https://github.com/dahall/ITaskHandlerTemplate.

AliceDev Oct 15 at 1:39 PM 
Hi, Can Microsoft.Win32.TaskScheduler call a VB Function/Method to perform a specific task within VB.Net like below :

td .Actions.Add(New ExecAction("MyMethod()", "c:\test.log"))

Sub MyMethod()
MsgBox("DONE !")
End Sub

I just need it to load/open xml file within VB.net (Not Outside) so that I can use nodes values and transfer content to variables.

Can it accomplish that? If not, can you point me to a right direction.

dahall Apr 8, 2015 at 5:00 PM 
aabdelhameed: If you email server supports putting passwords in header fields, you can use the HeaderFields property and add the name and the password as the value. If not, then I'm afraid this library will not support secured email accounts.

aabdelhameed Apr 7, 2015 at 5:28 PM 
about the EmailAction where to put the authenticated password of from account