c#使用多个远程桌面连接
源代码
http://www.codeproject.com/KB/cs/RemoteDesktopClient.aspx
你可以到上面的网址了解到更加详细的信息
效果图
下图的左边是一个远程列表,右边是MDI显示区域,可以显示多个远程界面。
下图是这个工具的说明,是使用Vs2008 RTM开发的,.Net版本是3.5Sp1。
源代码分析
相信大家对这个程序最感兴趣的地方是连接mstsc动态链接库的代码。
其中rdpClient 是AxMSTSCLib.AxMsRdpClient 类型对象。
声明如下:
public AxMSTSCLib.AxMsRdpClient rdpClient;
连接远程
{
Status("Starting ...");
rdpClient.Connect();
}
断开远程连接
public void Disconnect()
{
Status("Disconnecting ...");
rdpClient.DisconnectedText = "Disconnected";
if (rdpClient.Connected != 0)
{
rdpClient.Disconnect();
}
}
重新连接远程对象
连接的过程中需要指定服务器,用户名,密码等等。
public void Reconnect(bool hasChanges, bool isFitToWindow)
{
Disconnect();
Status("Waiting for the server to properly disconnect ...");
// wait for the server to properly disconnect
while (rdpClient.Connected != 0)
{
System.Threading.Thread.Sleep(1000);
Application.DoEvents();
}
Status("Reconnecting ...");
if (hasChanges)
{
rdpClient.Server = this._ss.Server;
rdpClient.UserName = this._ss.Username;
rdpClient.AdvancedSettings2.ClearTextPassword = this._ss.Password;
rdpClient.ColorDepth = this._ss.ColorDepth;
this._isFitToWindow = isFitToWindow;
if (isFitToWindow)
{
rdpClient.DesktopWidth = this.rdpClient.Width;
rdpClient.DesktopHeight = this.rdpClient.Height;
}
else
{
rdpClient.DesktopWidth = this._ss.DesktopWidth;
rdpClient.DesktopHeight = this._ss.DesktopHeight;
}
rdpClient.FullScreen = this._ss.Fullscreen;
}
Connect();
}
在连接的过程中,会使用大量Com接口函数。
这一程序,可以作为.Net实现远程桌面的重要参考。