mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
support local PowerShell connection
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user