寫在前面:使用Windows Server伺服器的朋友可以找到串連多個遠端桌面的功能,但使用Xp作業系統就不行了。遠端桌面功能就是使用mstsc這個檔案的。在system32檔案夾可以找到MSTSCAX.DLL這個動態串連庫,這是實現遠端連線的主要組件。下載介紹一個用C#編寫遠端桌面功能,可以串連多個Windows伺服器。
原始碼
http://www.codeproject.com/KB/cs/RemoteDesktopClient.aspx
你可以到上面的網址瞭解到更加詳細的資訊
的左邊是一個遠程列表,右邊是MDI顯示地區,可以顯示多個遠程介面。
是這個工具的說明,是使用Vs2008 RTM開發的,.Net版本是3.5Sp1。
原始碼分析
相信大家對這個程式最感興趣的地方是串連mstsc動態連結程式庫的代碼。
其中rdpClient 是AxMSTSCLib.AxMsRdpClient 類型對象。
聲明如下:
public AxMSTSCLib.AxMsRdpClient rdpClient;
串連遠程
public void Connect()//www.elivn.com
{
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實現遠端桌面的重要參考。
寫在前面:使用Windows Server伺服器的朋友可以找到串連多個遠端桌面的功能,但使用Xp作業系統就不行了。遠端桌面功能就是使用mstsc這個檔案的。在system32檔案夾可以找到MSTSCAX.DLL這個動態串連庫,這是實現遠端連線的主要組件。下載介紹一個用C#編寫遠端桌面功能,可以串連多個Windows伺服器。
原始碼
http://www.codeproject.com/KB/cs/RemoteDesktopClient.aspx
你可以到上面的網址瞭解到更加詳細的資訊
的左邊是一個遠程列表,右邊是MDI顯示地區,可以顯示多個遠程介面。
是這個工具的說明,是使用Vs2008 RTM開發的,.Net版本是3.5Sp1。
原始碼分析
相信大家對這個程式最感興趣的地方是串連mstsc動態連結程式庫的代碼。
其中rdpClient 是AxMSTSCLib.AxMsRdpClient 類型對象。
聲明如下:
public AxMSTSCLib.AxMsRdpClient rdpClient;
串連遠程
public void Connect()//www.elivn.com
{
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實現遠端桌面的重要參考。