代码之家  ›  专栏  ›  技术社区  ›  Simon Randy Burden

如何在WPF应用程序中主持终端会话(MSTSC)?

  •  2
  • Simon Randy Burden  · 技术社区  · 15 年前

    有一些工具可以管理多个终端(MSTSC)会话。

    在WPF中如何实现类似的目标?

    3 回复  |  直到 7 年前
        1
  •  3
  •   paulkore TcKs    12 年前

    你应该使用 WindowsFormsHost 元素以承载RDP的ActiveX控件。

    There is short sample 如何将Windows Media Player集成到WPF应用程序中。RDP控件的宿主类似。

        2
  •  1
  •   Mike Schenk    15 年前

    这些工具最有可能使用远程桌面ActiveX控件,该控件设计为在网页中承载,但由于它是一个ActiveX控件,因此您也应该能够单独承载它。

    如果没有其他内容,您可以在WPF应用程序中嵌入Web浏览器控件,然后将ActiveX控件嵌入其中。

    请参见以下链接:

        3
  •  0
  •   Alexander Phoenix    7 年前
    1. 您应该向项目2添加libs: axinterop.mstsclib.dll文件, 互操作.mstsclib.dll

    您可以从MS官方网站上的RDCMAN获得它。如何从“参考资料”中的“COM”选项卡添加它是一个很好的问题… 2。添加到xaml windowsformshost:

    <UserControl x:Class="VMViewer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="231" d:DesignWidth="274" Loaded="UserControl_Loaded">
    <Border BorderThickness="1" BorderBrush="CornflowerBlue">
        <Grid >
            <Grid.RowDefinitions>
                <RowDefinition Height="22"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Button Grid.Row="0" x:Name="connectBtn" Content="Connect" Click="Button_Click" DockPanel.Dock="Top" HorizontalAlignment="Stretch" />
            <WindowsFormsHost Grid.Row="1" Margin="0,0,0,0" x:Name="wfHost" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        </Grid>
    </Border>
    

    1. 创建新的RDP客户端类:

      公共类rdpcontrol:axmstsclib.axmsrdpclient9notsafeforscripting { 公共RDP控制() 基础() { }

      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
          {
              if (!this.ContainsFocus)
              {
                  this.Focus();
              }
          }
      
          base.WndProc(ref m);
      }}
      
    2. 在用户控件的后面代码中:

      私有void initdata() { _ rdp=新rdpcontrol(); ((system.componentModel.isupportInitialize)(_rdp)).begininit(); _ rdp.name=“rdp”; _ rdp.enabled=真; wfhost.child=rdp; ((system.componentModel.isupportInitialize)(_rdp)).endInit(); }

      private void Connect()
      {
          _rdp.Server = CurrentVM.Name;
          _rdp.UserName = CurrentVM.Login;
          _rdp.AdvancedSettings9.ClearTextPassword = CurrentVM.Password;
          _rdp.ColorDepth = 24;
          _rdp.AdvancedSettings9.SmartSizing = true;
          _rdp.AdvancedSettings9.AuthenticationLevel = 2;
          _rdp.AdvancedSettings9.EnableCredSspSupport = true;
          _rdp.Width = Convert.ToInt32(this.ActualWidth);
          _rdp.Height = Convert.ToInt32(this.ActualHeight);
          _rdp.DesktopWidth = Convert.ToInt32(this.ActualWidth);
          _rdp.DesktopHeight = Convert.ToInt32(this.ActualHeight);
          try
          {
              _rdp.Connect();
          }
          catch
          {
          }
      }
      
    3. 使用此处理程序添加到用户控件按钮:

      private void Button_Click(object sender, RoutedEventArgs e)
      {
          InitData();
          Connect();
      }
      

    希望它有帮助。