简体   繁体   English

如何从 .NET 核心控制台应用程序连接到 RDP 服务器?

[英]How to connect to a RDP Server from a .NET Core console app?

I'm creating a C# console app that acts as a client connecting to a RDP Server.我正在创建一个 C# 控制台应用程序,它充当连接到 RDP 服务器的客户端。 Both the client and server are on Linux machines.客户端和服务器都在Linux台机器上。 The target framework is .NET Core 3.1.目标框架是 .NET Core 3.1。

After some time investigating, I see that MSTSCLib is a viable option.经过一段时间的调查,我发现 MSTSCLib 是一个可行的选择。 But the code samples I found are old and documentations are sparse.但是我找到的代码示例很旧,文档也很少。

Here is what I managed to whip up so far:到目前为止,这是我设法完成的:

static void Main(string[] args)
        {
            var rdp = new MsTscAxNotSafeForScripting();

            rdp.Server = "10.0.0.1";
            rdp.UserName = "clientusername";

            rdp.Connect();
        }

I know that there are a lot missing in that code there so I appreciate any help or documents.我知道那里的代码中缺少很多东西,所以我很感激任何帮助或文件。 How do I know if my client successfully connects to the server or not?我怎么知道我的客户端是否成功连接到服务器?

You have to install RemoteDesktop library.您必须安装 RemoteDesktop 库。 You can install it via NuGet by running following command in package manager console:您可以通过 NuGet 在 package 管理器控制台中运行以下命令来安装它:

Install-Package RemoteDesktop

Here is an example to connect to RDP server using RemoteDesktop library:以下是使用 RemoteDesktop 库连接到 RDP 服务器的示例:

using RemoteDesktop;

var rdp = new RemoteDesktop.RemoteDesktop();
rdp.Server = "rdp.example.com";
rdp.Username = "username";
rdp.Password = "password";

rdp.Connect();

To disconnect from the RDP server, call the Disconnect method:要与 RDP 服务器断开连接,请调用 Disconnect 方法:

rdp.Disconnect();

You can also use other libraries and tools like FreeRDP, RemoteDesktopConnectionManager.您还可以使用其他库和工具,如 FreeRDP、RemoteDesktopConnectionManager。 I hope this might be helpful.我希望这可能会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 VS2019 中的 .NET Core 3.1 控制台应用程序连接到 Azure 文件存储 - How to connect to a Azure File Store from a .NET Core 3.1 console app in VS2019 无法从 RHEL 7 上的 .Net 核心应用程序连接到 SQL Server 数据库 - Not able to connect to a SQL Server db from .Net core app on RHEL 7 如何将 ASP NET web 应用程序客户端与 NET 框架控制台应用程序服务器连接 - How to connect ASP NET web app client with NET framework console app server 如何使用 .NET Core ZDB974238714CA8DE6434A7CE1DZ08A 调用从 .net 核心控制台应用程序创建的 dll - How to call a dll created from .net core console app using .NET Core API 如何使 .net 核心 3.1 控制台应用程序中的控制台记录器工作 - How to make console logger in .net core 3.1 console app work 如何确定.NET CORE DLL是否在Web服务器/主机或控制台应用程序中运行 - How to determine if .NET CORE DLL runs in Web server/host or Console App 无法从运行在 docker 上的 .net 核心应用连接到 SQL Server express - Can't connect to SQL Server express from .net core app running on docker .Net Core 应用程序:无法从远程 PC 连接到 Cassandra 1 节点服务器 - .Net Core app: Unable to connect to Cassandra 1 node server from a remote PC 在控制台应用程序中重用来自我的 ASP.NET Core MVC 应用程序的代码:如何进行数据库连接 - Reusing code from my ASP.NET Core MVC app in console app : how to do database connection 如何将.net框架数据层引用到.net核心控制台应用程序 - How reference .net framework data layer to .net core console app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM