Merge pull request #2533 from tommwq/v1.77.3-dev

support local PowerShell connection
This commit is contained in:
Dimitrij
2023-12-13 11:02:10 +00:00
committed by GitHub
3 changed files with 29 additions and 6 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);
}
}
}