diff --git a/mRemoteNG/Connection/ConnectionInitiator.cs b/mRemoteNG/Connection/ConnectionInitiator.cs index 4ea7e3b23..b13823730 100644 --- a/mRemoteNG/Connection/ConnectionInitiator.cs +++ b/mRemoteNG/Connection/ConnectionInitiator.cs @@ -76,10 +76,18 @@ namespace mRemoteNG.Connection } } - if (connectionInfo.Hostname == "" && connectionInfo.Protocol != ProtocolType.IntApp) + if (string.IsNullOrEmpty(connectionInfo.Hostname)) { - Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, Language.ConnectionOpenFailedNoHostname); - return; + if (!ProtocolFeature.SupportBlankHostname(connectionInfo.Protocol)) + { + Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, Language.ConnectionOpenFailedNoHostname); + return; + } + + if (string.IsNullOrEmpty(connectionInfo.Name)) + { + connectionInfo.Name = "localhost"; + } } StartPreConnectionExternalApp(connectionInfo); diff --git a/mRemoteNG/Connection/Protocol/PowerShell/Connection.Protocol.PowerShell.cs b/mRemoteNG/Connection/Protocol/PowerShell/Connection.Protocol.PowerShell.cs index cb8d0da97..52ad93ded 100644 --- a/mRemoteNG/Connection/Protocol/PowerShell/Connection.Protocol.PowerShell.cs +++ b/mRemoteNG/Connection/Protocol/PowerShell/Connection.Protocol.PowerShell.cs @@ -191,12 +191,19 @@ namespace mRemoteNG.Connection.Protocol.PowerShell // Setup process for script with arguments //* The -NoProfile parameter would be a valuable addition but should be able to be deactivated. - _consoleControl.StartProcess(psExe, $@"-NoExit -Command ""& {{ {psScriptBlock} }}"" -Hostname ""'{_connectionInfo.Hostname}'"" -Username ""'{psUsername}'"" -Password ""'{_connectionInfo.Password}'"" -LoginAttempts {psLoginAttempts}"); - + var arguments = $@"-NoExit -Command ""& {{ {psScriptBlock} }}"" -Hostname ""'{_connectionInfo.Hostname}'"" -Username ""'{psUsername}'"" -Password ""'{_connectionInfo.Password}'"" -LoginAttempts {psLoginAttempts}"; + var hostname = _connectionInfo.Hostname.Trim().ToLower(); + var useLocalHost = hostname == "" || hostname.Equals("localhost"); + if (useLocalHost) + { + arguments = $@"-NoExit"; + } + _consoleControl.StartProcess(psExe, arguments); + while (!_consoleControl.IsHandleCreated) break; _handle = _consoleControl.Handle; NativeMethods.SetParent(_handle, InterfaceControl.Handle); - + Resize(this, new EventArgs()); base.Connect(); return true; diff --git a/mRemoteNG/Connection/Protocol/ProtocolType.cs b/mRemoteNG/Connection/Protocol/ProtocolType.cs index 6f4016fdf..f4e1bd47e 100644 --- a/mRemoteNG/Connection/Protocol/ProtocolType.cs +++ b/mRemoteNG/Connection/Protocol/ProtocolType.cs @@ -38,4 +38,12 @@ namespace mRemoteNG.Connection.Protocol [LocalizedAttributes.LocalizedDescription(nameof(Language.ExternalTool))] IntApp = 20 } + + public class ProtocolFeature + { + public static bool SupportBlankHostname(ProtocolType protocolType) + { + return (protocolType == ProtocolType.IntApp || protocolType == ProtocolType.PowerShell); + } + } } \ No newline at end of file