先上圖:
我們可以調用ms的兩個組件來進行遠程桌面的連接與管理,這兩個組件分別是:
AxInterop.MSTSCLib.dll
Interop.MSTSCLib.dll
在(http://download.csdn.net/source/2652181)有示例代碼
代碼如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace RemoteDesktopClient
{
public partial class frmMain : Form
{
private AxMSTSCLib.AxMsRdpClient rdpc = null;
public frmMain()
{
InitializeComponent();
rdpc = new AxMSTSCLib.AxMsRdpClient();
rdpc.Dock = DockStyle.Fill;
this.tabPage1.Controls.Add(rdpc);
}
private void btnConnect_Click(object sender, EventArgs e)
{
try
{
rdpc.Server = this.txtServer.Text; //遠程桌面的IP地址或者域名
rdpc.Domain = ""; //遠程服務器所在的域
rdpc.UserName = this.txtUserName.Text; //系統用戶名
rdpc.AdvancedSettings2.ClearTextPassword = txtPassword.Text; //系統登錄密碼
rdpc.AdvancedSettings2.RedirectDrives = true;
rdpc.AdvancedSettings2.RedirectPrinters = true;
rdpc.ColorDepth = 32; //8,16,24,32
rdpc.DesktopHeight = this.tabPage1.Height-50;
rdpc.DesktopWidth = this.tabPage1.Width-50;
rdpc.Connect();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnDisconnect_Click(object sender, EventArgs e)
{
if (rdpc.Connected == 1)
rdpc.Disconnect();
}
}
}