diff --git a/Installer/version.txt b/Installer/version.txt index 300a4ce..f830089 100644 --- a/Installer/version.txt +++ b/Installer/version.txt @@ -1 +1 @@ -2.2.9.12 \ No newline at end of file +2.2.9.22 \ No newline at end of file diff --git a/src/Commands/CommandInvoker.cs b/src/Commands/CommandInvoker.cs index 97a92bd..1e711dd 100644 --- a/src/Commands/CommandInvoker.cs +++ b/src/Commands/CommandInvoker.cs @@ -78,7 +78,11 @@ public static CommandInvoker Create(string userCommandsFile, string currentVersi if (cmd.Enabled) { if (cmd.UserDefined) { +#if DEBUG + Logger.Instance.Log4.Debug($"{commands.GetType().Name}: User defined command enabled: '{cmd}'"); +#else Logger.Instance.Log4.Debug($"{commands.GetType().Name}: User defined command enabled: '****'"); +#endif } else { Logger.Instance.Log4.Debug($"{commands.GetType().Name}: Builtin command enabled: '{cmd}'"); diff --git a/src/Commands/SendMessageCommand.cs b/src/Commands/SendMessageCommand.cs index 826e4af..addf840 100644 --- a/src/Commands/SendMessageCommand.cs +++ b/src/Commands/SendMessageCommand.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Xml.Serialization; +using System.Linq; using Microsoft.Win32.Security; namespace MCEControl { @@ -31,10 +32,11 @@ public class SendMessageCommand : Command { private int wParam; [XmlAttribute("wparam")] public int WParam { get => wParam; set => wParam = value; } - [XmlAttribute("className")] - public String ClassName { get; set; } - [XmlAttribute("windowname")] - public String WindowName { get; set; } + private String className; + [XmlAttribute("classname")] public String ClassName { get => className; set => className = value; } + + private String windowName; + [XmlAttribute("windowname")] public String WindowName { get => windowName; set => windowName = value; } public static new List BuiltInCommands { get => new List() { @@ -69,26 +71,36 @@ public override bool Execute() { } try { - if (ClassName != null) { + if (!string.IsNullOrWhiteSpace(ClassName)) { var procs = Process.GetProcessesByName(ClassName); if (procs.Length > 0) { - var h = procs[0].MainWindowHandle; + var win = procs[0]; - Logger.Instance.Log4.Info($"{this.GetType().Name}: SendMessage {ToString()}"); - Win32.SendMessage(h, (DWORD)Msg, (DWORD)WParam, (DWORD)LParam); + if (!string.IsNullOrWhiteSpace(WindowName)) { + // Find MainWindowTitle matching WindowName + win = procs.FirstOrDefault(w => w.MainWindowTitle.Equals(WindowName)); + } + if (win == null) { + Logger.Instance.Log4.Error($"{this.GetType().Name}: Could not find a window of class '{ClassName}' captioned with '{WindowName}'"); + } + else { + Logger.Instance.Log4.Info($"{this.GetType().Name}: SendMessage(\"{win.MainWindowTitle}\", {Msg}, {WParam}, {LParam}) - {ToString()}"); + Win32.SendMessage(win.MainWindowHandle, (DWORD)Msg, (DWORD)WParam, (DWORD)LParam); + } } else { - Logger.Instance.Log4.Info($"{this.GetType().Name}: GetProcessByName for {ClassName} failed"); + Logger.Instance.Log4.Error($"{this.GetType().Name}: GetProcessByName for class '{ClassName}' failed"); } } - else { + else + { var h = Win32.GetForegroundWindow(); - Logger.Instance.Log4.Info($"{this.GetType().Name}: SendMessage (forground window): {ToString()}"); + Logger.Instance.Log4.Info($"{this.GetType().Name}: SendMessage(, {Msg}, {WParam}, {LParam}) - {ToString()}"); Win32.SendMessage(h, (DWORD)Msg, (DWORD)WParam, (DWORD)LParam); } } catch (Exception e) { - Logger.Instance.Log4.Error($"{this.GetType().Name}: Failed for {ClassName} with error: {e.Message}"); + Logger.Instance.Log4.Error($"{this.GetType().Name}: Failed for '{ClassName}' with error: {e.Message}"); return true; } return false; diff --git a/src/MCEControl.sln b/src/MCEControl.sln index 55bb8b8..25b9fa6 100644 --- a/src/MCEControl.sln +++ b/src/MCEControl.sln @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\Installer\Installer.tt = ..\Installer\Installer.tt Installer\license.txt = Installer\license.txt ..\Installer\logging.nsh = ..\Installer\logging.nsh + Win32\Readme.md = Win32\Readme.md README.md = README.md ..\Installer\version.txt = ..\Installer\version.txt EndProjectSection diff --git a/src/Win32/Readme.md b/src/Win32/Readme.md new file mode 100644 index 0000000..e9590e7 --- /dev/null +++ b/src/Win32/Readme.md @@ -0,0 +1,12 @@ +**Win32Security** + +This is a fork of a the Win32Security library from https://github.com/woanware/Win32Security. Originally written by +Renaud Paquay (is/was an Microsoft employee). woanwar modified it to include some service related access masks. https:://github.com/tig further modified it to work with modern .NET tools and versions of Windows, for use in https://github.com/tig/mcec. + +**Description** + +A C# library containing wrapper classes for ACL, ACE, Security descriptors, Security Attributes, Access tokens, etc. + +The original library was located here (no longer valid): + +http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=e6098575-dda0-48b8-9abf-e0705af065d9 \ No newline at end of file