由于Windows自帶遠(yuǎn)程桌面不帶管理列表,所以開發(fā)一款簡易遠(yuǎn)程桌面管理工具已備自用
- 利用COM組件遠(yuǎn)程桌面Rdp調(diào)用
- 首先在 Visual Studio 2017 中創(chuàng)建Windows窗體應(yīng)用程序
- 在工具欄中->右鍵->選擇項(xiàng),添加COM組件
- 通過拖拽到窗口中使用
我這里直接使用代碼動態(tài)創(chuàng)建窗體逃默,并動態(tài)創(chuàng)建
- 主要代碼如下:
// 動態(tài)創(chuàng)建一個新窗體,用于滿屏裝載遠(yuǎn)程桌面
Form form = new Form();
// 隱藏窗口Icon圖標(biāo)
form.ShowIcon = false;
//form.StartPosition = FormStartPosition.Manual;
// 窗口名稱摧茴,這里用傳過來的IP去掉.命名
form.Name = ServerIps[0].Replace(".", "");
// 窗口文本彰导,備注(IP地址)
form.Text = string.Format("{0} ({1})", args[3], ServerIps[0]);
// 窗口大小為 1024 * 768
form.Size = new Size(1024, 768);
// 獲取屏幕尺寸
Rectangle ScreenArea = Screen.PrimaryScreen.Bounds;
// 創(chuàng)建RdpClient
AxMsRdpClient7NotSafeForScripting axMsRdpc = new AxMsRdpClient7NotSafeForScripting();
((System.ComponentModel.ISupportInitialize)(axMsRdpc)).BeginInit();
axMsRdpc.Dock = DockStyle.Fill;
axMsRdpc.Enabled = true;
axMsRdpc.Name = string.Format("axMsRdpc_{0}", ServerIps[0].Replace(".", ""));
// 綁定連接與釋放事件
axMsRdpc.OnConnecting += new EventHandler(this.axMsRdpc_OnConnecting);
axMsRdpc.OnDisconnected += new IMsTscAxEvents_OnDisconnectedEventHandler(this.axMsRdpc_OnDisconnected);
// 將COM組件Rdpc添加到新窗口中
form.Controls.Add(axMsRdpc);
// 打開新窗口
form.Show();
((System.ComponentModel.ISupportInitialize)(axMsRdpc)).EndInit();
// 服務(wù)器地址
axMsRdpc.Server = ServerIps[0];
// 遠(yuǎn)程登錄賬號
axMsRdpc.UserName = args[1];
// 遠(yuǎn)程端口號
axMsRdpc.AdvancedSettings7.RDPPort = ServerIps.Length == 1 ? 3389 : Convert.ToInt32(ServerIps[1]);
// 自動控制屏幕顯示尺寸
//axMsRdpc.AdvancedSettings9.SmartSizing = true;
// 啟用CredSSP身份驗(yàn)證(有些服務(wù)器連接沒有反應(yīng)矢腻,需要開啟這個)
axMsRdpc.AdvancedSettings7.EnableCredSspSupport = true;
// 遠(yuǎn)程登錄密碼
axMsRdpc.AdvancedSettings7.ClearTextPassword = args[2];
// 顏色位數(shù) 8,16,24,32
axMsRdpc.ColorDepth = 32;
// 開啟全屏 true|flase
axMsRdpc.FullScreen = this.isFullScreen;
// 設(shè)置遠(yuǎn)程桌面寬度為顯示器寬度
axMsRdpc.DesktopWidth = ScreenArea.Width;
// 設(shè)置遠(yuǎn)程桌面寬度為顯示器高度
axMsRdpc.DesktopHeight = ScreenArea.Height;
// 遠(yuǎn)程連接
axMsRdpc.Connect();
-
通過以上一系列設(shè)置鞭衩,最終效果如下: