本篇文章主要介紹了c#實現windows遠程桌面連接程序代碼,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
使用winform制作windows遠程桌面連接程序,windows自帶了遠程桌面連接,我們需要將遠程桌面連接集成
到自己的winform程序,并實現管理遠程主機的配置。
遠程桌面核心類庫
windows系統自帶了遠程桌面activex dll,目錄:
c:WindowsSystem32mstscax.dll
此類庫無法使用c#直接調用,介紹一個工具AxImp.exe
AxImp.exe
msdn.microsoft.com/zh-cn/library/8ccdh774(VS.80).c#x
ActiveX c#導入程序將 ActiveX 控件的 COM 類型庫中的類型定義轉換為 Windows 窗體控件。
控件轉換
在cmd輸入以下命令
"c:Program?Files?(x86)Microsoft?SDKsWindowsv7.0ABinAxImp.exe"?"c:WindowsSystem32mstscax.dll"
即可生成AxMSTSCLib.dll,MSTSCLib.dll
遠程桌面連接核心代碼
//遠程連接核心方法 private?AxMSTSCLib.AxMsRdpClient7?rdpc?=?null; protected?void?OnCreateControl() { ??rdpc?=?new?AxMSTSCLib.AxMsRdpClient7(); ??rdpc.OnDisconnected?+=?new?AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEventHandler(rdpc_OnDisconnected); ??this.Controls.Add(rdpc); ??rdpc.Dock?=?DockStyle.Fill; ??rdpc.BringToFront(); } void?rdpc_OnDisconnected(object?sender,?AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent?e) { ??//處理斷開連接 } public?void?Disconnect() { ??try ??{ ????if?(rdpc.Connected?==?1) ????{ ??????rdpc.Disconnect(); ????} ??} ??catch?(Exception) ??{ ??} } private?void?SetRdpClientProperties(Machine?parMachine) { ??rdpc.Server?=?parMachine.MachineName; ??rdpc.AdvancedSettings2.RDPPort?=?parMachine.Port; ??rdpc.UserName?=?parMachine.UserName; ??rdpc.Domain?=?parMachine.DomainName; ??if?(parMachine.Password?!=?"") ??{ ????rdpc.AdvancedSettings5.ClearTextPassword?=?parMachine.Password; ??} ??rdpc.AdvancedSettings5.RedirectDrives?=?parMachine.ShareDiskDrives; ??rdpc.AdvancedSettings5.RedirectPrinters?=?parMachine.SharePrinters; ??rdpc.ColorDepth?=?(int)parMachine.ColorDepth; } public?void?Connect(Machine?parMachine) { ??SetRdpClientProperties(parMachine); ??rdpc.Connect(); } //遠程主機配置 [Serializable()] public?class?Machine { ??private?string?_RemoteDesktopConnectionName; ??public?string?RemoteDesktopConnectionName ??{ ????get?{?return?_RemoteDesktopConnectionName;?} ????set?{?_RemoteDesktopConnectionName?=?value;?} ??} ??private?string?_MachineName; ??public?string?MachineName ??{ ????get?{?return?_MachineName;?} ????set?{?_MachineName?=?value;?} ??} ??private?string?_DomainName; ??public?string?DomainName ??{ ????get?{?return?_DomainName;?} ????set?{?_DomainName?=?value;?} ??} ??private?string?_UserName; ??public?string?UserName ??{ ????get?{?return?_UserName;?} ????set?{?_UserName?=?value;?} ??} ??private?string?_Password; ??public?string?Password ??{ ????get?{?return?_Password;?} ????set?{?_Password?=?value;?} ??} ??private?bool?_AutoConnect; ??public?bool?AutoConnect ??{ ????get?{?return?_AutoConnect;?} ????set?{?_AutoConnect?=?value;?} ??} ??private?bool?_ShareDiskDrives; ??public?bool?ShareDiskDrives ??{ ????get?{?return?_ShareDiskDrives;?} ????set?{?_ShareDiskDrives?=?value;?} ??} ??private?bool?_SharePrinters; ??public?bool?SharePrinters ??{ ????get?{?return?_SharePrinters;?} ????set?{?_SharePrinters?=?value;?} ??} ??private?bool?_SavePassword; ??public?bool?SavePassword ??{ ????get?{?return?_SavePassword;?} ????set?{?_SavePassword?=?value;?} ??} ??private?Colors?_ColorDepth; ??public?Colors?ColorDepth ??{ ????get?{?return?_ColorDepth;?} ????set?{?_ColorDepth?=?value;?} ??} ??public?int?Port ??{ ????get ????{ ??????return?_Port; ????} ????set ????{ ??????_Port?=?value; ????} ??} ??private?int?_Port; ??public?enum?Colors ??{ ????HighColor15?=?15, ????HighColor16?=?16, ????Color256?=?8, ????TrueColor?=?24 ??} }
【相關推薦】
1.?c#
2.?c#
3.?c#
4.?c#
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END