简体   繁体   中英

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. Both the client and server are on Linux machines. The target framework is .NET Core 3.1.

After some time investigating, I see that MSTSCLib is a viable option. 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. You can install it via NuGet by running following command in package manager console:

Install-Package RemoteDesktop

Here is an example to connect to RDP server using RemoteDesktop library:

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();

You can also use other libraries and tools like FreeRDP, RemoteDesktopConnectionManager. I hope this might be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM