diff --git a/src/RoyalApps.Community.Rdp.WinForms/Configuration/RdpClientConfiguration.cs b/src/RoyalApps.Community.Rdp.WinForms/Configuration/RdpClientConfiguration.cs index 1533713..9c51b3e 100644 --- a/src/RoyalApps.Community.Rdp.WinForms/Configuration/RdpClientConfiguration.cs +++ b/src/RoyalApps.Community.Rdp.WinForms/Configuration/RdpClientConfiguration.cs @@ -1,20 +1,12 @@ -namespace RoyalApps.Community.Rdp.WinForms.Configuration; +using System; + +namespace RoyalApps.Community.Rdp.WinForms.Configuration; /// /// The remote desktop client configuration. /// public class RdpClientConfiguration { - /// - /// The client version to use. By default (value is 0) the highest available client will be used. - /// - public int ClientVersion { get; set; } - - /// - /// If true, Microsoft's Remote Desktop Client is used (when installed) instead of the legacy MSTSC ActiveX control. - /// - public bool UseMsRdc { get; set; } - /// /// Specifies the name of the server to which the current control is connected. /// The new server name. This parameter can be a DNS name or IP address. @@ -33,6 +25,11 @@ public class RdpClientConfiguration /// public int Port { get; set; } = 3389; + /// + /// The client version to use. By default (value is 0) the highest available client will be used. + /// + public int ClientVersion { get; set; } + /// /// Specifies the names of virtual channel client DLLs to be loaded. Virtual channel client DLLs are also referred to as Plug-in DLLs. /// Comma-separated list of the names of the virtual channel client DLLs to be loaded. The DLL names must contain only alphanumeric characters. @@ -41,6 +38,31 @@ public class RdpClientConfiguration /// https://docs.microsoft.com/en-us/windows/win32/termserv/imstscadvancedsettings-plugindlls /// public string? PluginDlls { get; set; } + + /// + /// If true, Microsoft's Remote Desktop Client is used (when installed) instead of the legacy MSTSC ActiveX control. + /// + public bool UseMsRdc { get; set; } + + /// + /// If set, the Microsoft Remote Desktop Client files (rdclientax.dll) will be searched here at first. + /// + public string? MsRdcPath { get; set; } + + /// + /// If true, a detailed log file will be written to the file system (see: LogFilePath) + /// + public bool LogEnabled { get; set; } + + /// + /// The following log levels are available: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF + /// + public string LogLevel { get; set; } = "TRACE"; + + /// + /// The file path to the log file when LogEnabled is set to true. + /// + public string LogFilePath { get; set; } = Environment.ExpandEnvironmentVariables(@"%TEMP%\MsRdpEx.log"); /// /// The credential configuration used to log on to the remote desktop session. diff --git a/src/RoyalApps.Community.Rdp.WinForms/Controls/RdpControl.cs b/src/RoyalApps.Community.Rdp.WinForms/Controls/RdpControl.cs index bea5326..23f7f62 100644 --- a/src/RoyalApps.Community.Rdp.WinForms/Controls/RdpControl.cs +++ b/src/RoyalApps.Community.Rdp.WinForms/Controls/RdpControl.cs @@ -35,13 +35,13 @@ public class RdpControl : UserControl private Size _previousClientSize = Size.Empty; private readonly Timer _timerResizeInProgress; - private readonly HashSet _rdClientSearchPaths = new() - { + private readonly HashSet _rdClientSearchPaths = + [ @"%ProgramFiles%\Remote Desktop", @"%ProgramFiles(x86)%\Remote Desktop", @"%ProgramFiles(ARM)%\Remote Desktop", @"%LocalAppData%\Apps\Remote Desktop" - }; + ]; /// /// Access to the RDP client and their events, methods and properties. @@ -541,6 +541,10 @@ private void CreateRdpClient() { RdpClient = RdpClientFactory.Create(RdpConfiguration.ClientVersion); + Environment.SetEnvironmentVariable("MSRDPEX_LOG_ENABLED", RdpConfiguration.LogEnabled ? "1" : "0"); + Environment.SetEnvironmentVariable("MSRDPEX_LOG_LEVEL", RdpConfiguration.LogLevel); + Environment.SetEnvironmentVariable("MSRDPEX_LOG_FILE_PATH", RdpConfiguration.LogFilePath); + var control = (Control) RdpClient; control.Dock = DockStyle.Fill; Controls.Add(control); @@ -550,14 +554,21 @@ private void CreateRdpClient() if (RdpConfiguration.UseMsRdc) { string? msRdcAxLibrary = null; - foreach (var path in _rdClientSearchPaths) + + if (!string.IsNullOrWhiteSpace(RdpConfiguration.MsRdcPath) && File.Exists(RdpConfiguration.MsRdcPath)) + msRdcAxLibrary = RdpConfiguration.MsRdcPath; + + if (string.IsNullOrWhiteSpace(msRdcAxLibrary)) { - var searchPath = Path.Combine(Environment.ExpandEnvironmentVariables(path), "rdclientax.dll"); - Logger.LogDebug("Searching file {SearchPath}", searchPath); - if (!Path.Exists(searchPath)) - continue; - msRdcAxLibrary = searchPath; - break; + foreach (var path in _rdClientSearchPaths) + { + var searchPath = Path.Combine(Environment.ExpandEnvironmentVariables(path), "rdclientax.dll"); + Logger.LogDebug("Searching file {SearchPath}", searchPath); + if (!Path.Exists(searchPath)) + continue; + msRdcAxLibrary = searchPath; + break; + } } if (string.IsNullOrWhiteSpace(msRdcAxLibrary)) @@ -568,6 +579,7 @@ private void CreateRdpClient() else { Environment.SetEnvironmentVariable("MSRDPEX_RDCLIENTAX_DLL", msRdcAxLibrary); + Environment.SetEnvironmentVariable("MSRDPEX_AXNAME", "msrdc"); Logger.LogInformation("Microsoft Remote Desktop Client will be used"); RdpClient.AxName = "msrdc";