C#实现远程机器管理_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > C#实现远程机器管理

C#实现远程机器管理

 2015/4/20 18:13:31  明月zq  程序员俱乐部  我要评论(0)
  • 摘要:目前处于待离职状态,原先所有的工作都在进行交接,过程当中不乏有很多先前整理的和动手尝试实现的功能;我的主页中已经列出来一部分内容,有兴趣的可以前往看一看。接下来的内容主要介绍另外一个工具,用于对远程主机进行远程控制、进程管理、服务管理以及WMI相关信息显示等;其中仍然存在部分问题还没有得到有效的解决,希望曾经参与过或者有关相关经验的前辈能够指导一下。一、很搓很搓的主界面1、配置菜单里面包括远程主机连接配置信息的添加和编辑,界面如下:2、功能菜单里面包括对远程主机远程控制、远程管理
  • 标签:C# 实现 远程

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

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

一、很搓很搓的主界面

QQZtuMIUEKQYTuOACUEGbbjCFBCkGE7jtuF8vypY7bfRAij4P724wJhVMt2HLcL5XD44EA4PPvuQx1PH3pleOJl/sLnpx62vTEgxKgwlJubm5ubm4VLKgHlwpk///Nw34VrXw6NXLs4k/3w87Xhs1dsbwwIMQqQVyanRCncDpHbgvLFyNn3Lt18+/zMJzfzQ6dTk3O50YvT27yV4211LpfL1dA4rnc05ne5XK7Wbvub3PlReSgVFrdJpHUoHzvwgnA9d3UhN7u8/lLk/PXl9ZEPr51JTKfP7hFiLSd7/9rf9WTf0aOR7v1F3crxtjpXQ53XVdfFa47yjV5XnbcBoDQVtkC5fY+0DmXi9d9f/CKfupEbv5pO395YWdto5wanPs5+cjl/NZVPCGvRxO1nz60+9sHqUnq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p/yLZ/eUsOEASicuyCicnB3yRAeg3FlQOl8AJUDpOAGUAKXjBFAClI5TJaCsyQAoyyeWZR9quvvRh909bfcOHv7pied/Xtq2o27fvp3JZBYXF+fn52/UkADK8oll2f379x87dmxkZOTKlSuzs7MlabL5+XlxHp4SGwxtm9oQQFk+sSzb2dl5/PjxCxcuzM3NrayslKTJxK8DyeVyFPrDKvdv38ovgLJ8YlmW47hwODw+Pp5Op7PZbEmaTLk+9VWNCqAsn1iWDQaDAwMDExMTmUwmn8+Xtu2ozRoVQFk+sSx76NCh11577dKlS8vLy+vr66VtO4CyVFASqyT0HwfKq4nIN3bIxRfOFkBpUZWGUsJN/y0dmThlhZv2tQf8/UVp+Rt5DSc8+N4AKC2r0ot8A9h6SlRiEUYrHQgYOSW2XFjrn/YvEdoAKC2rwl9GIPlYIFDAKRWfLHglFE+9pG73YsoNgNKyKvyKrbxI0hgZdTF6Sj/JE4vRjaB0gFcClBZV8Xd0lEXhNK35X6Pi+nN0P0S+tqhdU27wBRoOsEqA0qIqvPJc7SvSgQAdiIsZPR5QX4eQzzT42gLta99Gi33tt0qA0qLsmaeU37TVyczy8aKcUg9KcMqqVeWnhGT+4iEdp4yLpNJ0QafE5nyM+5QAZZWq0gMddRoxpQelTvomvztQnudER986bmu/UQKUVmVD+pamfNCZcAk5NCWLX1iFOySOYqEeo/0dyg2A0rKq6tk35n4F8jM80aluVRWUVSaA0qIAyvIJoLQogLJ8AigtCqAsnwBKiwIoyyeA0qLgH4aWTwClRZn7D8EgiyorlP8HHijWV3Tu5jAAAAAASUVORK5CYII=" alt="" />

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

WTPbHcUoXbgRtKvGyovvb7/7u59ceOITX3zvrifWz5y9cebUjXsXHjl5+A9LP9ZEoaF+RnVpRr3IsHOu1Zpb6L/CqyosvSTq0K75zYi+Ticmlxzu29Lu1gR5x3w7aLabfkZtaaaVXpowr/ky2x3FKF24kbX77PfePnf2+plTHy0dfvXwY6e+9pW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BAFLQLACAK2gUAEAXtAgCIgnYBAERBuwAAogysXYIgCCJnDKBdgiAIoohAuwRBEKKBdgmCIEQD7RIEQYgG2iUIghANtEsQBCEaG9olCIIgxOL/AdifTJpZz2AbAAAAAElFTkSuQmCC" alt="" />

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 sender, IMsTscAxEvents_OnDisconnectedEvent e)
        {

        }

        public bool Connect()
        {
            try
            {
                rdpc.Connect();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
        }

        public void Disconnect()
        {
            try
            {
                if (rdpc.Connected == 1)
                    rdpc.Disconnect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void SetRdpClientProperties(RemoteMachine machine)
        {
            rdpc.Server = machine.Server;
            rdpc.UserName = machine.UserName;
            rdpc.Domain = machine.Domain;
            if (!string.IsNullOrEmpty(machine.Password))
                rdpc.AdvancedSettings5.ClearTextPassword = machine.Password;
            rdpc.AdvancedSettings5.RedirectDrives = machine.RedirectDrives;
            rdpc.AdvancedSettings5.RedirectPrinters = machine.RedirectPrinters;
            rdpc.AdvancedSettings5.RedirectPorts = machine.RedirectPorts;
            rdpc.ColorDepth = (int)machine.ColorDepth;
            rdpc.Dock = DockStyle.Fill;
        }
    }

通过使用RemoteMachine参数实例化并进行远程控制;

                    RemoteMachine mac = item.Tag as RemoteMachine;
                    using (DesktopForm df = new DesktopForm(mac))
                    {
                        df.ShowDialog();
                    }

 2、进程、服务管理等(WMI方式,需要引人System.Management.dll类库,以进程管理为例,ProcessInfo类包含的属性信息可查询MSDN,其他类似)

    public partial class ProcessForm : Form, IRemote
    {
        private ManagementScope scope = null;
        private ManagementClass managementClass = null;
        private string path = null;
        public RemoteMachine Machine { get; set; }
        public ProcessForm(RemoteMachine machine)
        {
            InitializeComponent();
            Text = string.Format("【进程】{0}", machine.DesktopName);
            this.Machine = machine;
            this.path = "\\\\" + this.Machine.Server + "\\root\\cimv2:Win32_Process";
            this.managementClass = new ManagementClass(this.path);
            ConnectionOptions options = null;
            if (this.Machine.Server != "." && this.Machine.UserName != null && this.Machine.UserName.Length > 0)
            {
                options = new ConnectionOptions();
                options.Username = this.Machine.UserName;
                options.Password = this.Machine.Password;
                //options.EnablePrivileges = true;
                //options.Impersonation = ImpersonationLevel.Impersonate;
                //options.Authority = "ntlmdomain:domain"; 
            }
            this.scope = new ManagementScope("\\\\" + this.Machine.Server + "\\root\\cimv2", options);
            this.managementClass.Scope = this.scope;
        }

        private DataGridView dataGrid;
        private ContextMenuStrip contextMenu;
        private ProcessInfo[] processes;
        private void ProcessForm_Load(object sender, EventArgs e)
        {
            this.contextMenu = new ContextMenuStrip();
            ToolStripItem item = this.contextMenu.Items.Add("停止");
            item.Click += item_Click;
            this.dataGrid = new DataGridView() { Dock = DockStyle.Fill, ContextMenuStrip = this.contextMenu, SelectionMode = DataGridViewSelectionMode.FullRowSelect, AllowUserToAddRows = false, AllowUserToDeleteRows = false, ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize, ReadOnly = true, RowHeadersWidth = 21 };
            this.Controls.Add(this.dataGrid);
            ReLoad();
        }

        private void ReLoad()
        {
            this.dataGrid.DataSource = null;
            this.processes = null;
            if (Connect())
            {
                processes = GetProcess();
                DataTable table = ProcessInfo.ConvertTo(processes);
                BindData(table);
            }
        }

        private void item_Click(object sender, EventArgs e)
        {
            if (this.dataGrid.SelectedRows.Count == 1)
            {
                try
                {
                    UInt32 processId = Convert.ToUInt32(this.dataGrid.SelectedRows[0].Cells[0].Value);
                    string processName = this.dataGrid.SelectedRows[0].Cells[1].Value.ToString();
                    if (processName != null && MessageBox.Show(string.Format("是否停止\"{0}\"进程?", processName), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        ProcessInfo process = Array.Find(processes, (pro) => { return pro.Name == processName && pro.ProcessId == processId; });
                        KillProcess(process);
                        ReLoad();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                }
            }
        }

        public bool Connect()
        {
            try
            {
                scope.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return scope.IsConnected;
        }

        public void Disconnect()
        {

        }

        public void BindData(DataTable table)
        {
            this.dataGrid.DataSource = table;
        }

        public ProcessInfo[] GetProcess()
        {
            ManagementObjectCollection queryCollection = this.managementClass.GetInstances();
            List<ProcessInfo> processes = new List<ProcessInfo>();
            foreach (ManagementObject m in queryCollection)
            {
                ProcessInfo process = new ProcessInfo(m);
                processes.Add(process);
            }
            return processes.ToArray();
        }

        public void KillProcess(ProcessInfo process)
        {
            ObjectQuery query = new ObjectQuery(string.Format("select * from Win32_Process where ProcessId={0}", process.ProcessId));
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection queryCollection = searcher.Get();
            foreach (ManagementObject m in queryCollection)
            {
                string[] args = new string[] { "0" };
                object obj = m.InvokeMethod("Terminate", args);
                Console.WriteLine(obj.ToString());
                return;
            }
        }
    }

可以通过KillProcess来终止进程;

三、所遇到的问题

(未完待续...)

 

发表评论
用户名: 匿名