c#使用多個遠端桌面連線

來源:互聯網
上載者:User
寫在前面:使用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實現遠端桌面的重要參考。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.