分享
 
 
 

C#实现远程机器管理

王朝学院·作者佚名  2016-05-20
窄屏简体版  字體: |||超大  

C#实现远程机器管理 目前处于待离职状态,原先所有的工作都在进行交接,过程当中不乏有很多先前整理的和动手尝试实现的功能;我的主页中已经列出来一部分内容,有兴趣的可以前往看一看。

接下来的内容主要介绍另外一个工具,用于对远程主机进行远程控制、进程管理、服务管理以及WMI相关信息显示等;其中仍然存在部分问题还没有得到有效的解决,希望曾经参与过或者有关相关经验的前辈能够指导一下。

一、很搓很搓的主界面

1、配置菜单里面包括远程主机连接配置信息的添加和编辑,界面如下:

2、功能菜单里面包括对远程主机远程控制、远程管理、服务管理和WMI信息查询;

3、添加完成后,功能菜单会进行相应的变化,如下图:

二、主要功能实现部分

远程主机配置信息

public class RemoteMachine { /// <summary> /// 桌面名称 /// </summary> public string DesktopName { get { return this._DesktopName ?? this.Server; } set { this._DesktopName = value; } } PRivate string _DesktopName = null; /// <summary> /// 远程桌面的ip地址或者域名 /// </summary> public string Server { get; set; } /// <summary> /// 用户名 /// </summary> public string UserName { get; set; } /// <summary> /// IP /// </summary> public string Domain { get; set; } /// <summary> /// 登录密码 /// </summary> public string PassWord { get; set; } /// <summary> /// 允许查询进程 /// </summary> public bool ShowProcess { get { return _ShowProcess; } set { _ShowProcess = value; } } private bool _ShowProcess = true; /// <summary> /// 允许远程 /// </summary> public bool RemoteAble { get { return _RemoteAble; } set { _RemoteAble = value; } } private bool _RemoteAble = true; /// <summary> /// 允许查询服务 /// </summary> public bool ShowService { get { return _ShowService; } set { _ShowService = value; } } private bool _ShowService = true; /// <summary> /// 共享磁盘驱动器 /// </summary> public bool RedirectDrives { get { return _RedirectDrives; } set { _RedirectDrives = value; } } private bool _RedirectDrives = true; /// <summary> /// 共享打印机 /// </summary> public bool RedirectPrinters { get { return _RedirectPrinters; } set { _RedirectPrinters = value; } } private bool _RedirectPrinters = false; /// <summary> /// 共享端口 /// </summary> public bool RedirectPorts { get { return _RedirectPorts; } set { _RedirectPorts = value; } } private bool _RedirectPorts = false; /// <summary> /// 色彩深度 /// </summary> public Colors ColorDepth { get { return _ColorDepth; } set { _ColorDepth = value; } } private Colors _ColorDepth = Colors.Color24; public override string ToString() { return string.Format("{0}:{1}", this.DesktopName, this.Server); } public void Save(IniFile iniFile) { Save(this, iniFile); } public void Delete(IniFile iniFile) { string section = string.Format("Remote({0})", this.DesktopName); iniFile.DeleteSection(section); } public void Load(IniFile iniFile, string desktopName) { string section = string.Format("Remote({0})", desktopName); this.DesktopName = desktopName; this.Server = iniFile.ReadString(section, "Server", ""); this.UserName = iniFile.ReadString(section, "UserName", ""); this.Domain = iniFile.ReadString(section, "Domain", ""); this.Password = iniFile.ReadString(section, "Password", ""); this.RemoteAble = iniFile.ReadInt(section, "RemoteAble", 0) == 1; this.ShowProcess = iniFile.ReadInt(section, "ShowProcess", 0) == 1; this.ShowService = iniFile.ReadInt(section, "ShowService", 0) == 1; this.RedirectDrives = iniFile.ReadInt(section, "RedirectDrives", 0) == 1; this.RedirectPrinters = iniFile.ReadInt(section, "RedirectPrinters", 0) == 1; this.RedirectPorts = iniFile.ReadInt(section, "RedirectPorts", 0) == 1; this.ColorDepth = (Colors)iniFile.ReadInt(section, "ColorDepth", 0); } public static RemoteMachine Load(string desktopName, IniFile iniFile) { string section = string.Format("Remote({0})", desktopName); RemoteMachine mac = new RemoteMachine(); mac.DesktopName = desktopName; mac.Server = iniFile.ReadString(section, "Server", ""); mac.UserName = iniFile.ReadString(section, "UserName", ""); mac.Domain = iniFile.ReadString(section, "Domain", ""); mac.Password = iniFile.ReadString(section, "Password", ""); mac.RemoteAble = iniFile.ReadInt(section, "RemoteAble", 0) == 1; mac.ShowProcess = iniFile.ReadInt(section, "ShowProcess", 0) == 1; mac.ShowService = iniFile.ReadInt(section, "ShowService", 0) == 1; mac.RedirectDrives = iniFile.ReadInt(section, "RedirectDrives", 0) == 1; mac.RedirectPrinters = iniFile.ReadInt(section, "RedirectPrinters", 0) == 1; mac.RedirectPorts = iniFile.ReadInt(section, "RedirectPorts", 0) == 1; mac.ColorDepth = (Colors)iniFile.ReadInt(section, "ColorDepth", 0); return mac; } public static void Save(RemoteMachine machine, IniFile iniFile) { string section = string.Format("Remote({0})", machine.DesktopName); iniFile.WriteString(section, "DesktopName", machine.DesktopName); iniFile.WriteString(section, "Server", machine.Server); iniFile.WriteString(section, "UserName", machine.UserName); iniFile.WriteString(section, "Domain", machine.Domain); iniFile.WriteString(section, "Password", machine.Password); iniFile.WriteInt(section, "RemoteAble", machine.RemoteAble ? 1 : 0); iniFile.WriteInt(section, "ShowProcess", machine.ShowProcess ? 1 : 0); iniFile.WriteInt(section, "ShowService", machine.ShowService ? 1 : 0); iniFile.WriteInt(section, "RedirectDrives", machine.RedirectDrives ? 1 : 0); iniFile.WriteInt(section, "RedirectPrinters", machine.RedirectPrinters ? 1 : 0); iniFile.WriteInt(section, "RedirectPorts", machine.RedirectPorts ? 1 : 0); iniFile.WriteInt(section, "ColorDepth", (int)machine.ColorDepth); } public static List<RemoteMachine> Load(IniFile iniFile) { string[] infos = iniFile.ReadAllSectionNames(); if (infos != null) { List<RemoteMachine> macs = new List<RemoteMachine>(); foreach (string info in infos) { string section = info.Substring(7, info.Length - 8); RemoteMachine mac = RemoteMachine.Load(section, iniFile); macs.Add(mac); } return macs; } return null; } } public enum Colors : int { Color8 = 8, Color16 = 16, Color24 = 24, Color32 = 32 }

1、远程控制功能

工具内实现的远程控制功能需要引用AxInterop.MSTSCLib.dll和Interop.MSTSCLib.dll文件,具体代码如下:

public partial class DesktopForm : Form, IRemote { private AxMsRdpClient4 rdpc = null; public RemoteMachine Machine { get; set; } public DesktopForm(RemoteMachine machine) { InitializeComponent(); Text = string.Format("【远程】{0}", machine.DesktopName); this.Machine = machine; } private void DesktopForm_Load(object sender, EventArgs e) { this.rdpc = new AxMsRdpClient4() { Dock = DockStyle.Fill }; this.rdpc.OnDisconnected += rdpc_OnDisconnected; this.Controls.Add(this.rdpc); this.SetRdpClientProperties(this.Machine); Connect(); } private void rdpc_OnDisconnected(object send

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有