[英]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.