Added ConsoleControl, since it seems that the powershell.exe cannot be integrated

This commit is contained in:
Faryan Rezagholi
2019-09-08 13:02:58 +02:00
parent 35f6d3eb90
commit de3072c67e
5 changed files with 29 additions and 67 deletions

View File

@@ -140,3 +140,8 @@ Markdig
Copyright © 2016-2019 Alexandre Mutel
BSD 2-Clause "Simplified"
https://github.com/lunet-io/markdig
ConsoleControl
Copyright © 2015 Dave Kerr
MIT License
https://github.com/dwmkerr/consolecontrol

View File

@@ -6,7 +6,6 @@ using System.Threading;
using System.Windows.Forms;
using mRemoteNG.App;
using mRemoteNG.Messages;
using mRemoteNG.Tools;
namespace mRemoteNG.Connection.Protocol.PowerShell
{
@@ -15,8 +14,8 @@ namespace mRemoteNG.Connection.Protocol.PowerShell
#region Private Fields
private IntPtr _handle;
private Process _process;
private readonly ConnectionInfo _connectionInfo;
private ConsoleControl.ConsoleControl _consoleControl;
public ProtocolPowerShell(ConnectionInfo connectionInfo)
{
@@ -33,27 +32,24 @@ namespace mRemoteNG.Connection.Protocol.PowerShell
{
Runtime.MessageCollector?.AddMessage(MessageClass.InformationMsg,
$"Attempting to start remote PowerShell session.", true);
_process = new Process
_consoleControl = new ConsoleControl.ConsoleControl
{
StartInfo =
{
UseShellExecute = true,
FileName = @"C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell.exe",
Arguments = $@"-NoExit -Command ""$password = ConvertTo-SecureString '{_connectionInfo.Password}' -AsPlainText -Force; $cred = New-Object System.Management.Automation.PSCredential -ArgumentList @('{_connectionInfo.Domain}\{_connectionInfo.Username}', $password); Enter-PSSession -ComputerName {_connectionInfo.Hostname} -Credential $cred"""
},
EnableRaisingEvents = true,
Dock = DockStyle.Fill,
BackColor = Color.DarkBlue,
ForeColor = Color.White,
IsInputEnabled = true,
Padding = new Padding(0, 20, 0, 0)
};
_consoleControl.StartProcess(@"C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell.exe",
$@"-NoExit -Command ""$password = ConvertTo-SecureString '{_connectionInfo.Password}' -AsPlainText -Force; $cred = New-Object System.Management.Automation.PSCredential -ArgumentList @('{_connectionInfo.Domain}\{_connectionInfo.Username}', $password); Enter-PSSession -ComputerName {_connectionInfo.Hostname} -Credential $cred""");
_process.Exited += ProcessExited;
_process.Start();
_process.WaitForInputIdle();
NativeMethods.SetParent(_process.Handle, InterfaceControl.Handle);
while (!_consoleControl.IsHandleCreated) break;
_handle = _consoleControl.Handle;
NativeMethods.SetParent(_handle, InterfaceControl.Handle);
//Resize(this, new EventArgs());
Resize(this, new EventArgs());
base.Connect();
return true;
}
@@ -64,9 +60,6 @@ namespace mRemoteNG.Connection.Protocol.PowerShell
}
}
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public override void Focus()
{
try
@@ -96,51 +89,6 @@ namespace mRemoteNG.Connection.Protocol.PowerShell
}
}
public override void Close()
{
/* only attempt this if we have a valid process object
* Non-integrated tools will still call base.Close() and don't have a valid process object.
* See Connect() above... This just muddies up the log.
*/
if (_process != null)
{
try
{
if (!_process.HasExited)
{
_process.Kill();
}
}
catch (Exception ex)
{
Runtime.MessageCollector.AddExceptionMessage(Language.strIntAppKillFailed, ex);
}
try
{
if (!_process.HasExited)
{
_process.Dispose();
}
}
catch (Exception ex)
{
Runtime.MessageCollector.AddExceptionMessage(Language.strIntAppDisposeFailed, ex);
}
}
base.Close();
}
#endregion
#region Private Methods
private void ProcessExited(object sender, EventArgs e)
{
Event_Closed(this);
}
#endregion
#region Enumerations

BIN
mRemoteV1/Console.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -54,6 +54,12 @@
<Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="ConsoleControl, Version=1.2.1.0, Culture=neutral, PublicKeyToken=7edd23586f5e297f, processorArchitecture=MSIL">
<HintPath>..\packages\ConsoleControl.1.2.1\lib\net40-client\ConsoleControl.dll</HintPath>
</Reference>
<Reference Include="ConsoleControlAPI, Version=1.2.1.0, Culture=neutral, PublicKeyToken=7c86b8a36b9c33e2, processorArchitecture=MSIL">
<HintPath>..\packages\ConsoleControlAPI.1.2.1\lib\net40\ConsoleControlAPI.dll</HintPath>
</Reference>
<Reference Include="Geckofx-Core, Version=60.0.37.0, Culture=neutral, PublicKeyToken=3209ac31600d1857, processorArchitecture=x86">
<HintPath>..\packages\Geckofx60.32.60.0.37\lib\net45\Geckofx-Core.dll</HintPath>
</Reference>
@@ -1190,6 +1196,7 @@
</None>
<None Include="Documentation\images\connections_status.png" />
<None Include="Documentation\images\putty.png" />
<Content Include="Console.ico" />
<Content Include="Documentation\mssql_db_setup.sql" />
<Content Include="Documentation\mysql_db_setup.sql" />
<None Include="Documentation\images\config_top_bar.png" />

View File

@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.8.5" targetFramework="net46" />
<package id="ConsoleControl" version="1.2.1" targetFramework="net46" />
<package id="ConsoleControlAPI" version="1.2.1" targetFramework="net46" />
<package id="DockPanelSuite" version="3.0.6" targetFramework="net46" />
<package id="DockPanelSuite.ThemeVS2003" version="3.0.6" targetFramework="net46" />
<package id="DockPanelSuite.ThemeVS2012" version="3.0.6" targetFramework="net46" />