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

.net 如何在WPF应用程序中主持终端会话(mstsc)?,.net,wpf,remote-desktop,mstsc,.net,Wpf,Remote Desktop,Mstsc,有一些工具可用于管理多个终端(mstsc)会话 如何在WPF中实现类似的功能?这些工具最有可能使用远程桌面ActiveX控件,该控件设计为托管在网页中,但由于它是一个ActiveX控件,您也应该能够自己托管它 如果没有其他内容,您可以在WPF应用程序中嵌入web浏览器控件,然后将ActiveX控件嵌入其中 请参阅以下链接: 您应该使用WindowsFormsHost元素来托管RDP的ActiveX控件 如何将Windows Media Player集成到WPF应用程序中。RDP控件的宿主类

有一些工具可用于管理多个终端(mstsc)会话


如何在WPF中实现类似的功能?

这些工具最有可能使用远程桌面ActiveX控件,该控件设计为托管在网页中,但由于它是一个ActiveX控件,您也应该能够自己托管它

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

请参阅以下链接:


您应该使用
WindowsFormsHost
元素来托管RDP的ActiveX控件

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

  • 您应该向project中添加两个LIB: AxInterop.MSTSCLib.dll, Interop.MSTSCLib.dll
  • 你可以从微软官方网站上的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>
    
  • 用户控件的隐藏代码:

    私有void InitData() { _rdp=新的RdpControl(); ((System.ComponentModel.ISupportInitialize)(_rdp)).BeginInit(); _rdp.Name=“rdp”; _rdp.Enabled=true; wfHost.Child=\u rdp; ((System.ComponentModel.ISupportInitialize)(_rdp)).EndInit(); }

  • 使用此处理程序添加到UserControl按钮:

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

  • 希望有帮助。

    我需要做一些类似的事情,但是我想知道RDPControl是否有一个方法可以加载一个.rdp文件,其中包含带值的参数。这样,我们就可以更改值,而无需重新编译代码。我的目标是将其作为RemoteApp打开。
    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
        {
        }
    }
    
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        InitData();
        Connect();
    }