Event trigger by name now won't trigger disabled events.
     2 using System.Collections.Generic;
 
     3 using System.Diagnostics;
 
     6 using System.Runtime.Serialization;
 
     8 using System.Threading.Tasks;
 
    10 namespace SharpLib.Ear
 
    13     [AttributeObject(Id = "Action.Launch.App", Name = "Launch application", Description = "Launch an application.")]
 
    14     public class ActionLaunchApp : Action
 
    17         [AttributeObjectProperty
 
    19             Id = "Action.Launch.App.File",
 
    20             Name = "File to launch",
 
    21             Description = "Specifies the application file to launch.",
 
    22             Filter = "EXE files (*.exe)|*.exe"
 
    25         public PropertyFile File { get; set; } = new PropertyFile();
 
    28         [AttributeObjectProperty
 
    30             Id = "Action.Launch.App.SwitchTo",
 
    32             Description = "Specifies if we should switch the application if it's already launched."
 
    35         public bool SwitchTo { get; set; } = true;
 
    38         [AttributeObjectProperty
 
    40             Id = "Action.Launch.App.MultipleInstance",
 
    41             Name = "Multiple Instance",
 
    42             Description = "Specifies if We should launch multiple instance."
 
    45         public bool MultipleInstance { get; set; } = false;
 
    47         public override string BriefBase()
 
    49             return AttributeName + ": " + Path.GetFileName(File.FullPath);
 
    52         public override bool IsValid()
 
    54             // This is a valid configuration only if our file exists
 
    55             return System.IO.File.Exists(File.FullPath);
 
    58         [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SwitchToThisWindow")]
 
    59         public static extern void SwitchToThisWindow([System.Runtime.InteropServices.InAttribute()] System.IntPtr hwnd, [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] bool fUnknown);
 
    62         protected override async Task DoExecute()
 
    64             //First check if the process we want to launch already exists
 
    65             string procName = Path.GetFileNameWithoutExtension(File.FullPath);
 
    66             Process[] existingProcesses = Process.GetProcessesByName(procName);
 
    67             if (existingProcesses == null || existingProcesses.Length == 0 || MultipleInstance)
 
    69                 // Process do not exists just try to launch it
 
    70                 ProcessStartInfo start = new ProcessStartInfo();
 
    71                 // Enter in the command line arguments, everything you would enter after the executable name itself
 
    72                 //start.Arguments = arguments; 
 
    73                 // Enter the executable to run, including the complete path
 
    74                 start.FileName = File.FullPath;
 
    75                 start.WindowStyle = ProcessWindowStyle.Normal;
 
    76                 start.CreateNoWindow = true;
 
    77                 start.UseShellExecute = true;
 
    78                 // Run the external process & wait for it to finish
 
    79                 Process proc = Process.Start(start);
 
    81                 //SL: We could have used that too
 
    82                 //Shell32.Shell shell = new Shell32.Shell();
 
    83                 //shell.ShellExecute(Properties.Settings.Default.StartFileName);
 
    87                 //This won't work properly until we have a manifest that enables uiAccess.
 
    88                 //However uiAccess just won't work with ClickOnce so we will have to use a different deployment system.
 
    89                 SwitchToThisWindow(existingProcesses[0].MainWindowHandle, true);