-
Notifications
You must be signed in to change notification settings - Fork 196
ActionSamples
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";
// Show the dialog and have it return a new instance of an ExecAction
var dlg = new ActionEditDialog(null, false, AvailableActions.Execute);
if (dlg.ShowDialog() == DialogResult.Cancel) return;
// The new instance is in the Action property, which can be cast to the derived action type
var newAction = (ExecAction)dlg.Action;
// Create a dialog allowing the user to select from multiple action types
var dlg = new ActionEditDialog(null, false, AvailableActions.Execute | AvailableActions.ShowMessage);
// Create a dialog that allows the user to edit a single action
var action = new ExecAction("powershell");
var dlg = new ActionEditDialog(action, false, AvailableTriggers.Execute);
In Windows Vista and later, in the V2 library, there are three new actions. Under V1 systems (XP/WS2003 and earlier), these actions can be enabled via PowerShell by setting the TaskDefinition.Actions.PowerShellConversion
property to PowerShellActionPlatformOption.All
. Turning on support for PowerShell under V1 systems also allows 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...
The EmailAction
allows for an email to be sent when the task is triggered. It works as follows:
EmailAction eAction = new EmailAction("Task fired", "[email protected]", "[email protected]", "You just got a message", "smtp.company.com");
eAction.Cc = "[email protected]";
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 Releases 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.";