我正在编写一个 WPF UserControl,它使用 AxMSTSCLib 库托管 RemoteApp 会话。我正在使用来自这个 SO question的信息。我写的代码非常接近那个问题的答案。
我将 RemoteApp ActiveX (axMsRdpClient9NotSafeForScripting1) 放在我的 WPF UserControl 中,并在连接时提供必要的参数。
但问题是包含 UserControl 的 WPF 窗口打开但为空白。RemoteApp 实际启动但在主 WPF 窗口之外的单独窗口中。如何确保远程应用程序在 WPF UserControl 中打开?我错过了什么?
这是我的代码:
public void Connect()
{
try
{
axMsRdpClient9NotSafeForScripting1.UserName = @"domain\username";
axMsRdpClient9NotSafeForScripting1.Domain = "GTCS";
axMsRdpClient9NotSafeForScripting1.AdvancedSettings7.ClearTextPassword = "password";
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.AuthenticationLevel = 2;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.EnableCredSspSupport = true;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.NegotiateSecurityLayer = false;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RDPPort = 3389;
axMsRdpClient9NotSafeForScripting1.Server = "GT-DZ1-ATLS.GTCS.LOCAL"; // 10.24.141.199
axMsRdpClient9NotSafeForScripting1.RemoteProgram2.RemoteProgramMode = true;
axMsRdpClient9NotSafeForScripting1.OnConnected += (o, e) =>
{
m_connectionState = axMsRdpClient9NotSafeForScripting1.Connected;
((ITSRemoteProgram)((IMsRdpClient9)axMsRdpClient9NotSafeForScripting1.GetOcx()).RemoteProgram).ServerStartProgram(@"||startchrome", "", "", true, "", false);
//axMsRdpClient9NotSafeForScripting1.RemoteProgram.ServerStartProgram(@"||startchrome", "", "", true, "", false);
};
axMsRdpClient9NotSafeForScripting1.AdvancedSettings7.PublicMode = false;
axMsRdpClient9NotSafeForScripting1.DesktopWidth = SystemInformation.VirtualScreen.Width;
axMsRdpClient9NotSafeForScripting1.DesktopHeight = SystemInformation.VirtualScreen.Height;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.SmartSizing = true;
IMsTscNonScriptable secured = (IMsTscNonScriptable)axMsRdpClient9NotSafeForScripting1.GetOcx();
secured.ClearTextPassword = "password";
axMsRdpClient9NotSafeForScripting1.AdvancedSettings7.ClearTextPassword = "password";
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectClipboard = true;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectPrinters = true;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectPorts = false;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectSmartCards = true;
axMsRdpClient9NotSafeForScripting1.AdvancedSettings9.RedirectDrives = true;
axMsRdpClient9NotSafeForScripting1.Visible = true;
axMsRdpClient9NotSafeForScripting1.Enabled = true;
axMsRdpClient9NotSafeForScripting1.Connect();
m_connectionState = axMsRdpClient9NotSafeForScripting1.Connected;
}
catch (Exception ex)
{
var err = ex.Message;
MessageBox.Show(ex.Message);
}