mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-23 12:30:50 +01:00
CA-137236: Fix XenCenter Console crash when switching to remote desktop on Windows Server 2003 SP2
- Reverted "CP-4951: CAR-100: Remove Rdp2 console" because Rdpclient 6.0 is not included in Windows Server 2003 SP2; - Redone the fix for CA-123779 (Unhandled exception in Console Tab View), by moving RDPSetSettings() call inside a try..catch block, so we handle any exception thrown while setting the rdp client properties. Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
parent
4ac6f310ab
commit
8aadc063d4
@ -51,7 +51,15 @@ namespace XenAdmin.ConsoleView
|
||||
/// <summary>
|
||||
/// http://msdn2.microsoft.com/en-us/library/aa383022(VS.85).aspx
|
||||
/// </summary>
|
||||
private MsRdpClient6 rdpControl = null;
|
||||
private MsRdpClient6 rdpClient6 = null;
|
||||
|
||||
private MsRdpClient2 rdpClient2 = null;
|
||||
|
||||
/// <summary>
|
||||
/// This will be equal to rdpClient6, if the DLL that we've got is version 6, otherwise equal to
|
||||
/// rdpClient2.
|
||||
/// </summary>
|
||||
private AxHost rdpControl = null;
|
||||
|
||||
public event EventHandler OnDisconnected = null;
|
||||
|
||||
@ -61,30 +69,23 @@ namespace XenAdmin.ConsoleView
|
||||
this.size = size;
|
||||
try
|
||||
{
|
||||
rdpControl = new MsRdpClient6();
|
||||
rdpControl = rdpClient6 = new MsRdpClient6();
|
||||
RDPConfigure(size);
|
||||
|
||||
// CA-96135: Try adding rdpControl to parent.Controls list; this will throw exception when
|
||||
// MsRdpClient6 control cannot be created (there is no appropriate version of dll present)
|
||||
parent.Controls.Add(rdpControl);
|
||||
|
||||
RDPSetSettings();
|
||||
|
||||
rdpControl.Resize += resizeHandler;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch
|
||||
{
|
||||
Log.Error("MsRdpClient6 control cannot be added.", ex);
|
||||
|
||||
if (rdpControl != null)
|
||||
{
|
||||
if (parent.Controls.Contains(rdpControl))
|
||||
parent.Controls.Remove(rdpControl);
|
||||
|
||||
rdpControl.Dispose();
|
||||
rdpControl = null;
|
||||
}
|
||||
if (parent.Controls.Contains(rdpControl))
|
||||
parent.Controls.Remove(rdpControl);
|
||||
rdpClient6 = null;
|
||||
rdpControl = rdpClient2 = new MsRdpClient2();
|
||||
RDPConfigure(size);
|
||||
parent.Controls.Add(rdpControl);
|
||||
}
|
||||
rdpControl.Resize += resizeHandler;
|
||||
}
|
||||
|
||||
private void RDPConfigure(Size oldSize)
|
||||
@ -109,54 +110,79 @@ namespace XenAdmin.ConsoleView
|
||||
|
||||
private void RDPAddOnDisconnected()
|
||||
{
|
||||
if (rdpControl != null)
|
||||
rdpControl.OnDisconnected += rdpClient_OnDisconnected;
|
||||
if (rdpControl == null)
|
||||
return;
|
||||
|
||||
if (rdpClient6 == null)
|
||||
rdpClient2.OnDisconnected += rdpClient_OnDisconnected;
|
||||
else
|
||||
rdpClient6.OnDisconnected += rdpClient_OnDisconnected;
|
||||
}
|
||||
|
||||
private void RDPSetSettings()
|
||||
{
|
||||
if (rdpControl != null)
|
||||
if (rdpControl == null)
|
||||
return;
|
||||
|
||||
if (rdpClient6 == null)
|
||||
{
|
||||
rdpControl.SecuredSettings2.KeyboardHookMode = Properties.Settings.Default.WindowsShortcuts ? 1 : 0;
|
||||
rdpControl.SecuredSettings2.AudioRedirectionMode = Properties.Settings.Default.ReceiveSoundFromRDP ? 0 : 1;
|
||||
rdpControl.AdvancedSettings3.DisableRdpdr = Properties.Settings.Default.ClipboardAndPrinterRedirection ? 0 : 1;
|
||||
rdpControl.AdvancedSettings7.ConnectToAdministerServer = Properties.Settings.Default.ConnectToServerConsole;
|
||||
rdpClient2.SecuredSettings2.KeyboardHookMode = Properties.Settings.Default.WindowsShortcuts ? 1 : 0;
|
||||
rdpClient2.SecuredSettings2.AudioRedirectionMode = Properties.Settings.Default.ReceiveSoundFromRDP ? 0 : 1;
|
||||
rdpClient2.AdvancedSettings3.DisableRdpdr = Properties.Settings.Default.ClipboardAndPrinterRedirection ? 0 : 1;
|
||||
rdpClient2.AdvancedSettings2.ConnectToServerConsole = Properties.Settings.Default.ConnectToServerConsole;
|
||||
}
|
||||
else
|
||||
{
|
||||
rdpClient6.SecuredSettings2.KeyboardHookMode = Properties.Settings.Default.WindowsShortcuts ? 1 : 0;
|
||||
rdpClient6.SecuredSettings2.AudioRedirectionMode = Properties.Settings.Default.ReceiveSoundFromRDP ? 0 : 1;
|
||||
rdpClient6.AdvancedSettings3.DisableRdpdr = Properties.Settings.Default.ClipboardAndPrinterRedirection ? 0 : 1;
|
||||
rdpClient6.AdvancedSettings7.ConnectToAdministerServer = Properties.Settings.Default.ConnectToServerConsole;
|
||||
//CA-103910 - enable NLA for rdpClient6
|
||||
rdpControl.AdvancedSettings5.AuthenticationLevel = 2;
|
||||
rdpControl.AdvancedSettings7.EnableCredSspSupport = true;
|
||||
rdpClient6.AdvancedSettings5.AuthenticationLevel = 2;
|
||||
rdpClient6.AdvancedSettings7.EnableCredSspSupport = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void RDPConnect(string rdpIP, int w, int h)
|
||||
{
|
||||
if (rdpControl == null)
|
||||
return;
|
||||
|
||||
Log.DebugFormat("Connecting RDPClient{0} using server '{1}', width '{2}' and height '{3}'",
|
||||
rdpControl == null ? "2" : "6",
|
||||
rdpClient6 == null ? "2" : "6",
|
||||
rdpIP,
|
||||
w,
|
||||
h);
|
||||
|
||||
if (rdpControl != null)
|
||||
if (rdpClient6 == null)
|
||||
{
|
||||
rdpControl.Server = rdpIP;
|
||||
rdpControl.DesktopWidth = w;
|
||||
rdpControl.DesktopHeight = h;
|
||||
rdpControl.Connect();
|
||||
rdpClient2.Server = rdpIP;
|
||||
rdpClient2.DesktopWidth = w;
|
||||
rdpClient2.DesktopHeight = h;
|
||||
rdpClient2.Connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
rdpClient6.Server = rdpIP;
|
||||
rdpClient6.DesktopWidth = w;
|
||||
rdpClient6.DesktopHeight = h;
|
||||
rdpClient6.Connect();
|
||||
}
|
||||
}
|
||||
|
||||
private int Connected
|
||||
{
|
||||
get { return rdpControl == null ? 0 : rdpControl.Connected; }
|
||||
get { return rdpControl == null ? 0 : (rdpClient6 == null ? rdpClient2.Connected : rdpClient6.Connected); }
|
||||
}
|
||||
|
||||
private int DesktopHeight
|
||||
{
|
||||
get { return rdpControl == null ? 0 : rdpControl.DesktopHeight; }
|
||||
get { return rdpControl == null ? 0 : (rdpClient6 == null ? rdpClient2.DesktopHeight : rdpClient6.DesktopHeight); }
|
||||
}
|
||||
|
||||
private int DesktopWidth
|
||||
{
|
||||
get { return rdpControl == null ? 0 : rdpControl.DesktopWidth; }
|
||||
get { return rdpControl == null ? 0 : (rdpClient6 == null ? rdpClient2.DesktopWidth : rdpClient6.DesktopWidth); }
|
||||
}
|
||||
|
||||
private static readonly List<System.Windows.Forms.Timer> RdpCleanupTimers = new List<System.Windows.Forms.Timer>();
|
||||
@ -171,6 +197,18 @@ namespace XenAdmin.ConsoleView
|
||||
|
||||
public void Connect(string rdpIP)
|
||||
{
|
||||
try
|
||||
{
|
||||
RDPSetSettings();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (parent.Controls.Contains(rdpControl))
|
||||
parent.Controls.Remove(rdpControl);
|
||||
rdpControl.Dispose();
|
||||
rdpControl = null;
|
||||
Log.Error("Setting the RDP client properties caused an exception.", ex);
|
||||
}
|
||||
RDPConnect(rdpIP, size.Width, size.Height);
|
||||
}
|
||||
|
||||
@ -178,8 +216,13 @@ namespace XenAdmin.ConsoleView
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Connected == 1 && rdpControl != null)
|
||||
rdpControl.Disconnect();
|
||||
if (Connected == 1)
|
||||
{
|
||||
if (rdpClient6 == null)
|
||||
rdpClient2.Disconnect();
|
||||
else
|
||||
rdpClient6.Disconnect();
|
||||
}
|
||||
}
|
||||
catch(InvalidComObjectException ex)
|
||||
{
|
||||
@ -364,7 +407,7 @@ namespace XenAdmin.ConsoleView
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(rdpControl.Location.X, rdpControl.Location.Y, DesktopWidth, DesktopHeight);
|
||||
return rdpControl != null ? new Rectangle(rdpControl.Location.X, rdpControl.Location.Y, DesktopWidth, DesktopHeight) : Rectangle.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
51
XenAdmin/RDP/MsRdpClient2.cs
Normal file
51
XenAdmin/RDP/MsRdpClient2.cs
Normal file
@ -0,0 +1,51 @@
|
||||
/* Copyright (c) Citrix Systems Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
* with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the
|
||||
* following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace XenAdmin.RDP
|
||||
{
|
||||
public class MsRdpClient2 : AxMSTSCLib.AxMsRdpClient2
|
||||
{
|
||||
public MsRdpClient2()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void WndProc(ref System.Windows.Forms.Message m)
|
||||
{
|
||||
//Fix for the missing focus issue on the rdp client component
|
||||
if (m.Msg == 0x0021) //WM_MOUSEACTIVATE ref:http://msdn.microsoft.com/en-us/library/ms645612(VS.85).aspx
|
||||
{
|
||||
this.Select();
|
||||
}
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
}
|
||||
}
|
@ -2569,6 +2569,9 @@
|
||||
<DependentUpon>LVMoHBAWarningDialog.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Network\XenConnectionUI.cs" />
|
||||
<Compile Include="RDP\MsRdpClient2.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RDP\MsRdpClient6.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
|
Loading…
Reference in New Issue
Block a user