From 7b7534310259bcfcc2725aedd74463e7afe8753a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=83=E7=82=B9=E5=B7=A5=E5=9D=8A?= Date: Mon, 16 Mar 2020 11:02:36 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E9=A1=B9=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiMay.Core/MessageHead.cs | 6 + SiMay.Core/Packets/SysManager/ProcessInfo.cs | 11 + .../Packets/SysManager/SystemInfoPack.cs | 4 + .../ApplicationService/SystemService.cs | 139 +++++ .../SystemAdapterHandler.cs | 29 ++ .../Application/SystemApplication.Designer.cs | 474 ++++++++++++------ .../Application/SystemApplication.cs | 89 ++++ .../Application/SystemApplication.resx | 9 +- .../UserControls/ProcessListviewitem.cs | 51 ++ 9 files changed, 653 insertions(+), 159 deletions(-) diff --git a/SiMay.Core/MessageHead.cs b/SiMay.Core/MessageHead.cs index 2994501..305df70 100644 --- a/SiMay.Core/MessageHead.cs +++ b/SiMay.Core/MessageHead.cs @@ -116,12 +116,18 @@ namespace SiMay.Core S_SYSTEM_GET_OCCUPY, //获取系统占用率信息 S_SYSTEM_ENUMSESSIONS, //获取所有会话信息 S_SYSTEM_CREATE_USER_PROCESS, //创建用户进程 + S_SYSTEM_SERVICE_LIST, //服务列表 + S_SYSTEM_SERVICE_STOP, //停止服务 + S_SYSTEM_SERVICE_START, //启动服务 + S_SYSTEM_SERVICE_RESTART, //重启服务 + S_SYSTEM_SERVICE_STARTTYPE_SET, //设置服务启动方式 //接收指令 C_SYSTEM_PROCESS_LIST = 2000, //进程列表 C_SYSTEM_SYSTEMINFO, //系统信息 C_SYSTEM_OCCUPY_INFO, //系统占用率信息 C_SYSTEM_SESSIONS, //会话信息 + C_SYSTEM_SERVICE_LIST, //服务列表 //键盘记录--------------------------------------------------------------- S_KEYBOARD_ONOPEN = 1000, //窗口打开 diff --git a/SiMay.Core/Packets/SysManager/ProcessInfo.cs b/SiMay.Core/Packets/SysManager/ProcessInfo.cs index 5d93b75..57a97c7 100644 --- a/SiMay.Core/Packets/SysManager/ProcessInfo.cs +++ b/SiMay.Core/Packets/SysManager/ProcessInfo.cs @@ -23,4 +23,15 @@ namespace SiMay.Core.Packets public string User { get; set; } public string FilePath { get; set; } } + + public class ServiceItem : EntitySerializerBase + { + public string ServiceName { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + public string Status { get; set; } + public string UserName { get; set; } + public string StartType { get; set; } + public string FilePath { get; set; } + } } diff --git a/SiMay.Core/Packets/SysManager/SystemInfoPack.cs b/SiMay.Core/Packets/SysManager/SystemInfoPack.cs index 4028553..f2dbec2 100644 --- a/SiMay.Core/Packets/SysManager/SystemInfoPack.cs +++ b/SiMay.Core/Packets/SysManager/SystemInfoPack.cs @@ -26,4 +26,8 @@ namespace SiMay.Core.Packets public string ItemName { get; set; } public string Value { get; set; } } + public class ServiceInfoPack : EntitySerializerBase + { + public ServiceItem[] ServiceList { get; set; } + } } diff --git a/SiMay.RemoteClient.NewCore/ApplicationService/SystemService.cs b/SiMay.RemoteClient.NewCore/ApplicationService/SystemService.cs index 4f32ae2..f419334 100644 --- a/SiMay.RemoteClient.NewCore/ApplicationService/SystemService.cs +++ b/SiMay.RemoteClient.NewCore/ApplicationService/SystemService.cs @@ -1,4 +1,5 @@ using Microsoft.VisualBasic.Devices; +using Microsoft.Win32; using SiMay.Basic; using SiMay.Core; using SiMay.Core.Common; @@ -280,5 +281,143 @@ namespace SiMay.ServiceCore MemoryUsage = (_memoryInfo.TotalPhysicalMemory / 1024 / 1024).ToString() + "MB/" + ((_memoryInfo.TotalPhysicalMemory - _memoryInfo.AvailablePhysicalMemory) / 1024 / 1024).ToString() + "MB" }); } + + + [PacketHandler(MessageHead.S_SYSTEM_SERVICE_LIST)] + public void GetServiceList(TcpSocketSaeaSession session) => this.SendServiceList(); + + [PacketHandler(MessageHead.S_SYSTEM_SERVICE_START)] + public void Service_Start(TcpSocketSaeaSession session) + { + var serviceItem = GetMessageEntity(session); + try + { + using (var sc = new System.ServiceProcess.ServiceController(serviceItem.ServiceName)) + { + if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped)) + { + sc.Start(); + } + } + } + catch { } + + SendServiceList(); + + } + + [PacketHandler(MessageHead.S_SYSTEM_SERVICE_STOP)] + public void Service_Stop(TcpSocketSaeaSession session) + { + var serviceItem = GetMessageEntity(session); + try + { + using (var sc = new System.ServiceProcess.ServiceController(serviceItem.ServiceName)) + { + if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Running)) + { + sc.Stop(); + } + } + } + catch { } + + SendServiceList(); + + } + + [PacketHandler(MessageHead.S_SYSTEM_SERVICE_RESTART)] + public void Service_ReStart(TcpSocketSaeaSession session) + { + var serviceItem = GetMessageEntity(session); + try + { + using (var sc = new System.ServiceProcess.ServiceController(serviceItem.ServiceName)) + { + if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped)) + { + sc.Start(); + } + if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Running)) + { + sc.Stop(); + while (true) + { + System.Threading.Thread.Sleep(1000); + if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped)) + { + sc.Start(); + break; + } + } + } + } + } + catch { } + + SendServiceList(); + + } + + [PacketHandler(MessageHead.S_SYSTEM_SERVICE_STARTTYPE_SET)] + public void Service_StartType(TcpSocketSaeaSession session) + { + var serviceItem = GetMessageEntity(session); + try + { + Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + serviceItem.ServiceName, true)?.SetValue("Start", serviceItem.StartType, RegistryValueKind.DWord); + } + catch { } + SendServiceList(); + + } + + private void SendServiceList() + { + var serviceList = System.ServiceProcess.ServiceController.GetServices() + .OrderBy(s => s.ServiceName) + .Select(c => new ServiceItem() + { + ServiceName = c.ServiceName, + DisplayName = c.DisplayName, + Description = GetDescription(c.ServiceName), + Status = c.Status.ToString(), + StartType = c.StartType.ToString(), + UserName = GetLoginUserName(c.ServiceName), + FilePath = GetImagePath(c.ServiceName) + }).ToArray(); + + SendTo(CurrentSession, MessageHead.C_SYSTEM_SERVICE_LIST, + new ServiceInfoPack() + { + ServiceList = serviceList + }); + } + + private string GetDescription(string serviceName) + { + string ReturnValue = string.Empty; + using (var management = new System.Management.ManagementObject(new System.Management.ManagementPath(string.Format("Win32_Service.Name='{0}'", serviceName)))) + { + try + { + ReturnValue = management["Description"].ToString(); + } + catch + { + ReturnValue = (string)Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + serviceName)?.GetValue("Description") ?? string.Empty; + } + + } + return ReturnValue; + } + private string GetLoginUserName(string serviceName) + { + return (string)Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + serviceName)?.GetValue("ObjectName") ?? string.Empty; + } + private string GetImagePath(string serviceName) + { + return (string)Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + serviceName)?.GetValue("ImagePath") ?? string.Empty; + } } } \ No newline at end of file diff --git a/SiMay.RemoteControlsCore/ApplicationAdapterHandlers/SystemAdapterHandler.cs b/SiMay.RemoteControlsCore/ApplicationAdapterHandlers/SystemAdapterHandler.cs index 60c51fa..7a36891 100644 --- a/SiMay.RemoteControlsCore/ApplicationAdapterHandlers/SystemAdapterHandler.cs +++ b/SiMay.RemoteControlsCore/ApplicationAdapterHandlers/SystemAdapterHandler.cs @@ -107,5 +107,34 @@ namespace SiMay.RemoteControlsCore.HandlerAdapters }); } + public event Action> OnServicesListEventHandler; + + [PacketHandler(MessageHead.C_SYSTEM_SERVICE_LIST)] + private void ServiceItemHandler(SessionProviderContext session) + { + var serviceList = GetMessageEntity(session).ServiceList; + OnServicesListEventHandler?.Invoke(this, serviceList); + } + + public void Service_GetList() + { + SendTo(CurrentSession, MessageHead.S_SYSTEM_SERVICE_LIST); + } + public void Service_Stop(ServiceItem serviceItems) + { + SendTo(CurrentSession, MessageHead.S_SYSTEM_SERVICE_STOP, serviceItems); + } + public void Service_Strat(ServiceItem serviceItems) + { + SendTo(CurrentSession, MessageHead.S_SYSTEM_SERVICE_START, serviceItems); + } + public void Service_ReStrat(ServiceItem serviceItems) + { + SendTo(CurrentSession, MessageHead.S_SYSTEM_SERVICE_RESTART, serviceItems); + } + public void Service_StartType_Set(ServiceItem serviceItems) + { + SendTo(CurrentSession, MessageHead.S_SYSTEM_SERVICE_STARTTYPE_SET, serviceItems); + } } } diff --git a/SiMay.RemoteMonitor/Application/SystemApplication.Designer.cs b/SiMay.RemoteMonitor/Application/SystemApplication.Designer.cs index 35b0143..b164ba1 100644 --- a/SiMay.RemoteMonitor/Application/SystemApplication.Designer.cs +++ b/SiMay.RemoteMonitor/Application/SystemApplication.Designer.cs @@ -36,9 +36,35 @@ namespace SiMay.RemoteMonitor.Application this.button4 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); + this.processList = new SiMay.RemoteMonitor.UserControls.UListView(); this.tabPage3 = new System.Windows.Forms.TabPage(); this.button1 = new System.Windows.Forms.Button(); + this.sessionsListView = new SiMay.RemoteMonitor.UserControls.UListView(); + this.userName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.sessionId = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.state = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.windowsStationName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.userProcessCreated = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.tabPage2 = new System.Windows.Forms.TabPage(); + this.systemInfoList = new SiMay.RemoteMonitor.UserControls.UListView(); + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.tabPage4 = new System.Windows.Forms.TabPage(); + this.serviceList = new SiMay.RemoteMonitor.UserControls.UListView(); + this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.munServiceList = new System.Windows.Forms.ContextMenuStrip(this.components); + this.tmunStart = new System.Windows.Forms.ToolStripMenuItem(); + this.tmunStop = new System.Windows.Forms.ToolStripMenuItem(); + this.tmunReStart = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.tmunAutomatic = new System.Windows.Forms.ToolStripMenuItem(); + this.tmunManual = new System.Windows.Forms.ToolStripMenuItem(); + this.tmunDisable = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.关闭窗口ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -56,20 +82,12 @@ namespace SiMay.RemoteMonitor.Application this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel(); this.moryUse = new System.Windows.Forms.ToolStripStatusLabel(); this.refreshTimer = new System.Windows.Forms.Timer(this.components); - this.processList = new SiMay.RemoteMonitor.UserControls.UListView(); - this.sessionsListView = new SiMay.RemoteMonitor.UserControls.UListView(); - this.userName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.sessionId = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.state = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.windowsStationName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.userProcessCreated = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.systemInfoList = new SiMay.RemoteMonitor.UserControls.UListView(); - this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); this.tabPage3.SuspendLayout(); this.tabPage2.SuspendLayout(); + this.tabPage4.SuspendLayout(); + this.munServiceList.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -82,11 +100,12 @@ namespace SiMay.RemoteMonitor.Application this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage3); this.tabControl1.Controls.Add(this.tabPage2); - this.tabControl1.Location = new System.Drawing.Point(9, 36); - this.tabControl1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabControl1.Controls.Add(this.tabPage4); + this.tabControl1.Location = new System.Drawing.Point(5, 23); + this.tabControl1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(821, 538); + this.tabControl1.Size = new System.Drawing.Size(624, 435); this.tabControl1.TabIndex = 0; // // tabPage1 @@ -96,21 +115,21 @@ namespace SiMay.RemoteMonitor.Application this.tabPage1.Controls.Add(this.button3); this.tabPage1.Controls.Add(this.button2); this.tabPage1.Controls.Add(this.processList); - this.tabPage1.Location = new System.Drawing.Point(4, 25); - this.tabPage1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabPage1.Location = new System.Drawing.Point(4, 22); + this.tabPage1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.tabPage1.Name = "tabPage1"; - this.tabPage1.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.tabPage1.Size = new System.Drawing.Size(813, 509); + this.tabPage1.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage1.Size = new System.Drawing.Size(616, 409); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "进程管理"; // // button4 // this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button4.Location = new System.Drawing.Point(425, 462); - this.button4.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.button4.Location = new System.Drawing.Point(401, 387); + this.button4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button4.Name = "button4"; - this.button4.Size = new System.Drawing.Size(117, 30); + this.button4.Size = new System.Drawing.Size(66, 19); this.button4.TabIndex = 14; this.button4.Text = "最小化"; this.button4.UseVisualStyleBackColor = true; @@ -119,10 +138,10 @@ namespace SiMay.RemoteMonitor.Application // button3 // this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button3.Location = new System.Drawing.Point(551, 462); - this.button3.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.button3.Location = new System.Drawing.Point(472, 387); + this.button3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(117, 30); + this.button3.Size = new System.Drawing.Size(66, 19); this.button3.TabIndex = 13; this.button3.Text = "最大化"; this.button3.UseVisualStyleBackColor = true; @@ -131,24 +150,42 @@ namespace SiMay.RemoteMonitor.Application // button2 // this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button2.Location = new System.Drawing.Point(676, 462); - this.button2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.button2.Location = new System.Drawing.Point(542, 387); + this.button2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(117, 30); + this.button2.Size = new System.Drawing.Size(66, 19); this.button2.TabIndex = 12; this.button2.Text = "结束进程"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // + // processList + // + this.processList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.processList.BackColor = System.Drawing.SystemColors.ControlLightLight; + this.processList.CheckBoxes = true; + this.processList.FullRowSelect = true; + this.processList.HideSelection = false; + this.processList.Location = new System.Drawing.Point(10, 11); + this.processList.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.processList.Name = "processList"; + this.processList.Size = new System.Drawing.Size(600, 373); + this.processList.TabIndex = 11; + this.processList.UseCompatibleStateImageBehavior = false; + this.processList.UseWindowsThemStyle = true; + this.processList.View = System.Windows.Forms.View.Details; + // // tabPage3 // this.tabPage3.Controls.Add(this.button1); this.tabPage3.Controls.Add(this.sessionsListView); - this.tabPage3.Location = new System.Drawing.Point(4, 25); - this.tabPage3.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabPage3.Location = new System.Drawing.Point(4, 22); + this.tabPage3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.tabPage3.Name = "tabPage3"; - this.tabPage3.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.tabPage3.Size = new System.Drawing.Size(813, 509); + this.tabPage3.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage3.Size = new System.Drawing.Size(616, 409); this.tabPage3.TabIndex = 2; this.tabPage3.Text = "会话管理"; this.tabPage3.UseVisualStyleBackColor = true; @@ -156,27 +193,232 @@ namespace SiMay.RemoteMonitor.Application // button1 // this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button1.Location = new System.Drawing.Point(676, 461); - this.button1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.button1.Location = new System.Drawing.Point(542, 386); + this.button1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(117, 30); + this.button1.Size = new System.Drawing.Size(66, 19); this.button1.TabIndex = 13; this.button1.Text = "创建用户进程"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // + // sessionsListView + // + this.sessionsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.sessionsListView.BackColor = System.Drawing.SystemColors.ControlLightLight; + this.sessionsListView.CheckBoxes = true; + this.sessionsListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.userName, + this.sessionId, + this.state, + this.windowsStationName, + this.userProcessCreated}); + this.sessionsListView.FullRowSelect = true; + this.sessionsListView.HideSelection = false; + this.sessionsListView.Location = new System.Drawing.Point(10, 11); + this.sessionsListView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.sessionsListView.Name = "sessionsListView"; + this.sessionsListView.Size = new System.Drawing.Size(600, 371); + this.sessionsListView.TabIndex = 12; + this.sessionsListView.UseCompatibleStateImageBehavior = false; + this.sessionsListView.UseWindowsThemStyle = true; + this.sessionsListView.View = System.Windows.Forms.View.Details; + // + // userName + // + this.userName.Text = "用户名"; + this.userName.Width = 100; + // + // sessionId + // + this.sessionId.Text = "会话标识"; + this.sessionId.Width = 100; + // + // state + // + this.state.Text = "会话状态"; + this.state.Width = 100; + // + // windowsStationName + // + this.windowsStationName.Text = "窗口站"; + this.windowsStationName.Width = 100; + // + // userProcessCreated + // + this.userProcessCreated.Text = "被控用户进程"; + this.userProcessCreated.Width = 100; + // // tabPage2 // this.tabPage2.BackColor = System.Drawing.SystemColors.ButtonHighlight; this.tabPage2.Controls.Add(this.systemInfoList); - this.tabPage2.Location = new System.Drawing.Point(4, 25); - this.tabPage2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabPage2.Location = new System.Drawing.Point(4, 22); + this.tabPage2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.tabPage2.Name = "tabPage2"; - this.tabPage2.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.tabPage2.Size = new System.Drawing.Size(813, 509); + this.tabPage2.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage2.Size = new System.Drawing.Size(616, 409); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "系统信息"; // + // systemInfoList + // + this.systemInfoList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.systemInfoList.BackColor = System.Drawing.SystemColors.ButtonHighlight; + this.systemInfoList.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.systemInfoList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1, + this.columnHeader2}); + this.systemInfoList.FullRowSelect = true; + this.systemInfoList.HideSelection = false; + this.systemInfoList.Location = new System.Drawing.Point(4, 5); + this.systemInfoList.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.systemInfoList.Name = "systemInfoList"; + this.systemInfoList.Size = new System.Drawing.Size(609, 407); + this.systemInfoList.TabIndex = 12; + this.systemInfoList.UseCompatibleStateImageBehavior = false; + this.systemInfoList.UseWindowsThemStyle = true; + this.systemInfoList.View = System.Windows.Forms.View.Details; + // + // columnHeader1 + // + this.columnHeader1.Text = "信息项"; + this.columnHeader1.Width = 150; + // + // columnHeader2 + // + this.columnHeader2.Text = "值"; + this.columnHeader2.Width = 300; + // + // tabPage4 + // + this.tabPage4.Controls.Add(this.serviceList); + this.tabPage4.Location = new System.Drawing.Point(4, 22); + this.tabPage4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage4.Name = "tabPage4"; + this.tabPage4.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage4.Size = new System.Drawing.Size(616, 409); + this.tabPage4.TabIndex = 3; + this.tabPage4.Text = "服务信息"; + this.tabPage4.UseVisualStyleBackColor = true; + // + // serviceList + // + this.serviceList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader3, + this.columnHeader4, + this.columnHeader5, + this.columnHeader6, + this.columnHeader7, + this.columnHeader8}); + this.serviceList.ContextMenuStrip = this.munServiceList; + this.serviceList.Dock = System.Windows.Forms.DockStyle.Fill; + this.serviceList.FullRowSelect = true; + this.serviceList.HideSelection = false; + this.serviceList.Location = new System.Drawing.Point(2, 2); + this.serviceList.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.serviceList.Name = "serviceList"; + this.serviceList.Size = new System.Drawing.Size(612, 405); + this.serviceList.TabIndex = 0; + this.serviceList.UseCompatibleStateImageBehavior = false; + this.serviceList.UseWindowsThemStyle = true; + this.serviceList.View = System.Windows.Forms.View.Details; + // + // columnHeader3 + // + this.columnHeader3.Text = "服务名称"; + this.columnHeader3.Width = 87; + // + // columnHeader4 + // + this.columnHeader4.Text = "服务显示名称"; + this.columnHeader4.Width = 149; + // + // columnHeader5 + // + this.columnHeader5.Text = "描述"; + this.columnHeader5.Width = 100; + // + // columnHeader6 + // + this.columnHeader6.Text = "状态"; + this.columnHeader6.Width = 81; + // + // columnHeader7 + // + this.columnHeader7.Text = "启动类型"; + this.columnHeader7.Width = 82; + // + // columnHeader8 + // + this.columnHeader8.Text = "登陆为"; + this.columnHeader8.Width = 99; + // + // munServiceList + // + this.munServiceList.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.munServiceList.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.tmunStart, + this.tmunStop, + this.tmunReStart, + this.toolStripSeparator1, + this.tmunAutomatic, + this.tmunManual, + this.tmunDisable}); + this.munServiceList.Name = "munServiceList"; + this.munServiceList.Size = new System.Drawing.Size(101, 142); + // + // tmunStart + // + this.tmunStart.Name = "tmunStart"; + this.tmunStart.Size = new System.Drawing.Size(100, 22); + this.tmunStart.Text = "启动"; + this.tmunStart.Click += new System.EventHandler(this.tmunStart_Click); + // + // tmunStop + // + this.tmunStop.Name = "tmunStop"; + this.tmunStop.Size = new System.Drawing.Size(100, 22); + this.tmunStop.Text = "停止"; + this.tmunStop.Click += new System.EventHandler(this.tmunStop_Click); + // + // tmunReStart + // + this.tmunReStart.Name = "tmunReStart"; + this.tmunReStart.Size = new System.Drawing.Size(100, 22); + this.tmunReStart.Text = "重启"; + this.tmunReStart.Click += new System.EventHandler(this.tmunReStart_Click); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(97, 6); + // + // tmunAutomatic + // + this.tmunAutomatic.Name = "tmunAutomatic"; + this.tmunAutomatic.Size = new System.Drawing.Size(100, 22); + this.tmunAutomatic.Text = "自动"; + this.tmunAutomatic.Click += new System.EventHandler(this.tmunAutomatic_Click); + // + // tmunManual + // + this.tmunManual.Name = "tmunManual"; + this.tmunManual.Size = new System.Drawing.Size(100, 22); + this.tmunManual.Text = "手动"; + this.tmunManual.Click += new System.EventHandler(this.tmunManual_Click); + // + // tmunDisable + // + this.tmunDisable.Name = "tmunDisable"; + this.tmunDisable.Size = new System.Drawing.Size(100, 22); + this.tmunDisable.Text = "禁用"; + this.tmunDisable.Click += new System.EventHandler(this.tmunDisable_Click); + // // menuStrip1 // this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); @@ -185,7 +427,8 @@ namespace SiMay.RemoteMonitor.Application this.刷新信息ToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1049, 38); + this.menuStrip1.Padding = new System.Windows.Forms.Padding(3, 2, 0, 2); + this.menuStrip1.Size = new System.Drawing.Size(629, 25); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // @@ -194,13 +437,13 @@ namespace SiMay.RemoteMonitor.Application this.文件ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.关闭窗口ToolStripMenuItem}); this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem"; - this.文件ToolStripMenuItem.Size = new System.Drawing.Size(53, 34); + this.文件ToolStripMenuItem.Size = new System.Drawing.Size(44, 21); this.文件ToolStripMenuItem.Text = "文件"; // // 关闭窗口ToolStripMenuItem // this.关闭窗口ToolStripMenuItem.Name = "关闭窗口ToolStripMenuItem"; - this.关闭窗口ToolStripMenuItem.Size = new System.Drawing.Size(152, 26); + this.关闭窗口ToolStripMenuItem.Size = new System.Drawing.Size(124, 22); this.关闭窗口ToolStripMenuItem.Text = "关闭窗口"; this.关闭窗口ToolStripMenuItem.Click += new System.EventHandler(this.关闭窗口ToolStripMenuItem_Click); // @@ -210,13 +453,13 @@ namespace SiMay.RemoteMonitor.Application this.立即刷新ToolStripMenuItem, this.更新速度ToolStripMenuItem}); this.刷新信息ToolStripMenuItem.Name = "刷新信息ToolStripMenuItem"; - this.刷新信息ToolStripMenuItem.Size = new System.Drawing.Size(53, 34); + this.刷新信息ToolStripMenuItem.Size = new System.Drawing.Size(44, 21); this.刷新信息ToolStripMenuItem.Text = "选项"; // // 立即刷新ToolStripMenuItem // this.立即刷新ToolStripMenuItem.Name = "立即刷新ToolStripMenuItem"; - this.立即刷新ToolStripMenuItem.Size = new System.Drawing.Size(152, 26); + this.立即刷新ToolStripMenuItem.Size = new System.Drawing.Size(124, 22); this.立即刷新ToolStripMenuItem.Text = "立即刷新"; this.立即刷新ToolStripMenuItem.Click += new System.EventHandler(this.立即刷新ToolStripMenuItem_Click); // @@ -228,13 +471,13 @@ namespace SiMay.RemoteMonitor.Application this.低ToolStripMenuItem, this.暂停ToolStripMenuItem}); this.更新速度ToolStripMenuItem.Name = "更新速度ToolStripMenuItem"; - this.更新速度ToolStripMenuItem.Size = new System.Drawing.Size(152, 26); + this.更新速度ToolStripMenuItem.Size = new System.Drawing.Size(124, 22); this.更新速度ToolStripMenuItem.Text = "更新速度"; // // 高ToolStripMenuItem // this.高ToolStripMenuItem.Name = "高ToolStripMenuItem"; - this.高ToolStripMenuItem.Size = new System.Drawing.Size(122, 26); + this.高ToolStripMenuItem.Size = new System.Drawing.Size(100, 22); this.高ToolStripMenuItem.Text = "高"; this.高ToolStripMenuItem.Click += new System.EventHandler(this.高ToolStripMenuItem_Click); // @@ -243,21 +486,21 @@ namespace SiMay.RemoteMonitor.Application this.正常ToolStripMenuItem.Checked = true; this.正常ToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; this.正常ToolStripMenuItem.Name = "正常ToolStripMenuItem"; - this.正常ToolStripMenuItem.Size = new System.Drawing.Size(122, 26); + this.正常ToolStripMenuItem.Size = new System.Drawing.Size(100, 22); this.正常ToolStripMenuItem.Text = "正常"; this.正常ToolStripMenuItem.Click += new System.EventHandler(this.正常ToolStripMenuItem_Click); // // 低ToolStripMenuItem // this.低ToolStripMenuItem.Name = "低ToolStripMenuItem"; - this.低ToolStripMenuItem.Size = new System.Drawing.Size(122, 26); + this.低ToolStripMenuItem.Size = new System.Drawing.Size(100, 22); this.低ToolStripMenuItem.Text = "低"; this.低ToolStripMenuItem.Click += new System.EventHandler(this.低ToolStripMenuItem_Click); // // 暂停ToolStripMenuItem // this.暂停ToolStripMenuItem.Name = "暂停ToolStripMenuItem"; - this.暂停ToolStripMenuItem.Size = new System.Drawing.Size(122, 26); + this.暂停ToolStripMenuItem.Size = new System.Drawing.Size(100, 22); this.暂停ToolStripMenuItem.Text = "暂停"; this.暂停ToolStripMenuItem.Click += new System.EventHandler(this.暂停ToolStripMenuItem_Click); // @@ -270,43 +513,43 @@ namespace SiMay.RemoteMonitor.Application this.cpuUse, this.toolStripStatusLabel2, this.moryUse}); - this.statusStrip1.Location = new System.Drawing.Point(0, 578); + this.statusStrip1.Location = new System.Drawing.Point(0, 460); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 19, 0); + this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 10, 0); this.statusStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.ManagerRenderMode; - this.statusStrip1.Size = new System.Drawing.Size(839, 30); + this.statusStrip1.Size = new System.Drawing.Size(629, 26); this.statusStrip1.TabIndex = 2; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusLabel1 // this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; - this.toolStripStatusLabel1.Size = new System.Drawing.Size(58, 24); + this.toolStripStatusLabel1.Size = new System.Drawing.Size(47, 21); this.toolStripStatusLabel1.Text = "进程数:"; // // m_proNum // this.m_proNum.BorderSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.Right; this.m_proNum.Name = "m_proNum"; - this.m_proNum.Size = new System.Drawing.Size(22, 24); + this.m_proNum.Size = new System.Drawing.Size(19, 21); this.m_proNum.Text = "0"; // // cpuUse // this.cpuUse.Name = "cpuUse"; - this.cpuUse.Size = new System.Drawing.Size(114, 24); + this.cpuUse.Size = new System.Drawing.Size(93, 21); this.cpuUse.Text = "CPU 使用率:0%"; // // toolStripStatusLabel2 // this.toolStripStatusLabel2.Name = "toolStripStatusLabel2"; - this.toolStripStatusLabel2.Size = new System.Drawing.Size(504, 24); + this.toolStripStatusLabel2.Size = new System.Drawing.Size(363, 21); this.toolStripStatusLabel2.Spring = true; // // moryUse // this.moryUse.Name = "moryUse"; - this.moryUse.Size = new System.Drawing.Size(121, 24); + this.moryUse.Size = new System.Drawing.Size(96, 21); this.moryUse.Text = "内存:1024/1024"; // // refreshTimer @@ -315,114 +558,15 @@ namespace SiMay.RemoteMonitor.Application this.refreshTimer.Interval = 1500; this.refreshTimer.Tick += new System.EventHandler(this.RefreshTimer_Tick); // - // processList - // - this.processList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.processList.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.processList.CheckBoxes = true; - this.processList.FullRowSelect = true; - this.processList.HideSelection = false; - this.processList.Location = new System.Drawing.Point(17, 18); - this.processList.Margin = new System.Windows.Forms.Padding(4); - this.processList.Name = "processList"; - this.processList.Size = new System.Drawing.Size(775, 438); - this.processList.TabIndex = 11; - this.processList.UseCompatibleStateImageBehavior = false; - this.processList.UseWindowsThemStyle = true; - this.processList.View = System.Windows.Forms.View.Details; - // - // sessionsListView - // - this.sessionsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.sessionsListView.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.sessionsListView.CheckBoxes = true; - this.sessionsListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.userName, - this.sessionId, - this.state, - this.windowsStationName, - this.userProcessCreated}); - this.sessionsListView.FullRowSelect = true; - this.sessionsListView.HideSelection = false; - this.sessionsListView.Location = new System.Drawing.Point(17, 18); - this.sessionsListView.Margin = new System.Windows.Forms.Padding(4); - this.sessionsListView.Name = "sessionsListView"; - this.sessionsListView.Size = new System.Drawing.Size(775, 435); - this.sessionsListView.TabIndex = 12; - this.sessionsListView.UseCompatibleStateImageBehavior = false; - this.sessionsListView.UseWindowsThemStyle = true; - this.sessionsListView.View = System.Windows.Forms.View.Details; - // - // userName - // - this.userName.Text = "用户名"; - this.userName.Width = 100; - // - // sessionId - // - this.sessionId.Text = "会话标识"; - this.sessionId.Width = 100; - // - // state - // - this.state.Text = "会话状态"; - this.state.Width = 100; - // - // windowsStationName - // - this.windowsStationName.Text = "窗口站"; - this.windowsStationName.Width = 100; - // - // userProcessCreated - // - this.userProcessCreated.Text = "被控用户进程"; - this.userProcessCreated.Width = 100; - // - // systemInfoList - // - this.systemInfoList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.systemInfoList.BackColor = System.Drawing.SystemColors.ButtonHighlight; - this.systemInfoList.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.systemInfoList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.columnHeader1, - this.columnHeader2}); - this.systemInfoList.FullRowSelect = true; - this.systemInfoList.HideSelection = false; - this.systemInfoList.Location = new System.Drawing.Point(8, 8); - this.systemInfoList.Margin = new System.Windows.Forms.Padding(4); - this.systemInfoList.Name = "systemInfoList"; - this.systemInfoList.Size = new System.Drawing.Size(795, 494); - this.systemInfoList.TabIndex = 12; - this.systemInfoList.UseCompatibleStateImageBehavior = false; - this.systemInfoList.UseWindowsThemStyle = true; - this.systemInfoList.View = System.Windows.Forms.View.Details; - // - // columnHeader1 - // - this.columnHeader1.Text = "信息项"; - this.columnHeader1.Width = 150; - // - // columnHeader2 - // - this.columnHeader2.Text = "值"; - this.columnHeader2.Width = 300; - // // SystemApplication // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(839, 608); + this.ClientSize = new System.Drawing.Size(629, 486); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.tabControl1); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "SystemApplication"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "SystemManager"; @@ -432,6 +576,8 @@ namespace SiMay.RemoteMonitor.Application this.tabPage1.ResumeLayout(false); this.tabPage3.ResumeLayout(false); this.tabPage2.ResumeLayout(false); + this.tabPage4.ResumeLayout(false); + this.munServiceList.ResumeLayout(false); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.statusStrip1.ResumeLayout(false); @@ -478,5 +624,21 @@ namespace SiMay.RemoteMonitor.Application private System.Windows.Forms.ColumnHeader windowsStationName; private System.Windows.Forms.ColumnHeader userProcessCreated; private System.Windows.Forms.Button button1; + private System.Windows.Forms.TabPage tabPage4; + private UListView serviceList; + private System.Windows.Forms.ColumnHeader columnHeader3; + private System.Windows.Forms.ColumnHeader columnHeader4; + private System.Windows.Forms.ColumnHeader columnHeader5; + private System.Windows.Forms.ColumnHeader columnHeader6; + private System.Windows.Forms.ColumnHeader columnHeader7; + private System.Windows.Forms.ColumnHeader columnHeader8; + private System.Windows.Forms.ContextMenuStrip munServiceList; + private System.Windows.Forms.ToolStripMenuItem tmunStart; + private System.Windows.Forms.ToolStripMenuItem tmunStop; + private System.Windows.Forms.ToolStripMenuItem tmunReStart; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripMenuItem tmunAutomatic; + private System.Windows.Forms.ToolStripMenuItem tmunManual; + private System.Windows.Forms.ToolStripMenuItem tmunDisable; } } \ No newline at end of file diff --git a/SiMay.RemoteMonitor/Application/SystemApplication.cs b/SiMay.RemoteMonitor/Application/SystemApplication.cs index 471203c..630ea65 100644 --- a/SiMay.RemoteMonitor/Application/SystemApplication.cs +++ b/SiMay.RemoteMonitor/Application/SystemApplication.cs @@ -71,6 +71,9 @@ namespace SiMay.RemoteMonitor.Application this.SystemAdapterHandler.GetSystemInfoItems(); this.SystemAdapterHandler.EnumSession(); this.GetSystemInfos(); + + this.SystemAdapterHandler.OnServicesListEventHandler += OnServicesListEventHandler; + this.SystemAdapterHandler.Service_GetList(); } private void OnSessionsEventHandler(SystemAdapterHandler adapterHandler, IEnumerable sessions) @@ -297,5 +300,91 @@ namespace SiMay.RemoteMonitor.Application this.SystemAdapterHandler.EnumSession(); } + + private void OnServicesListEventHandler(SystemAdapterHandler adapterHandler, IEnumerable serviceItems) + { + this.serviceList.Items.Clear(); + var serviceList = new List(serviceItems); + foreach (var item in serviceList) + { + var serviceitem = new ServiceViewItem(item.ServiceName, item.DisplayName, item.Description, item.Status, item.StartType, item.UserName); + this.serviceList.Items.Add(serviceitem); + } + } + + private void tmunStart_Click(object sender, EventArgs e) + { + if (serviceList.SelectedItems.Count > 0) + { + ListView.SelectedListViewItemCollection selectItem = this.serviceList.SelectedItems; + this.SystemAdapterHandler.Service_Strat(new ServiceItem() + { + ServiceName = selectItem[0].Text + }); + } + } + + private void tmunStop_Click(object sender, EventArgs e) + { + if (serviceList.SelectedItems.Count > 0) + { + ListView.SelectedListViewItemCollection selectItem = this.serviceList.SelectedItems; + this.SystemAdapterHandler.Service_Stop(new ServiceItem() + { + ServiceName = selectItem[0].Text + }); + } + } + + private void tmunReStart_Click(object sender, EventArgs e) + { + if (serviceList.SelectedItems.Count > 0) + { + ListView.SelectedListViewItemCollection selectItem = this.serviceList.SelectedItems; + this.SystemAdapterHandler.Service_ReStrat(new ServiceItem() + { + ServiceName = selectItem[0].Text + }); + } + } + + private void tmunAutomatic_Click(object sender, EventArgs e) + { + if (serviceList.SelectedItems.Count > 0) + { + ListView.SelectedListViewItemCollection selectItem = this.serviceList.SelectedItems; + this.SystemAdapterHandler.Service_StartType_Set(new ServiceItem() + { + ServiceName = selectItem[0].Text, + StartType = "2" + }); + } + } + + private void tmunManual_Click(object sender, EventArgs e) + { + if (serviceList.SelectedItems.Count > 0) + { + ListView.SelectedListViewItemCollection selectItem = this.serviceList.SelectedItems; + this.SystemAdapterHandler.Service_StartType_Set(new ServiceItem() + { + ServiceName = selectItem[0].Text, + StartType = "3" + }); + } + } + + private void tmunDisable_Click(object sender, EventArgs e) + { + if (serviceList.SelectedItems.Count > 0) + { + ListView.SelectedListViewItemCollection selectItem = this.serviceList.SelectedItems; + this.SystemAdapterHandler.Service_StartType_Set(new ServiceItem() + { + ServiceName = selectItem[0].Text, + StartType = "4" + }); + } + } } } \ No newline at end of file diff --git a/SiMay.RemoteMonitor/Application/SystemApplication.resx b/SiMay.RemoteMonitor/Application/SystemApplication.resx index a566c40..2ff891c 100644 --- a/SiMay.RemoteMonitor/Application/SystemApplication.resx +++ b/SiMay.RemoteMonitor/Application/SystemApplication.resx @@ -117,14 +117,17 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 + + 157, 17 + - 137, 17 + 277, 17 - 258, 17 + 398, 17 47 diff --git a/SiMay.RemoteMonitor/UserControls/ProcessListviewitem.cs b/SiMay.RemoteMonitor/UserControls/ProcessListviewitem.cs index e79cc79..55c2fc2 100644 --- a/SiMay.RemoteMonitor/UserControls/ProcessListviewitem.cs +++ b/SiMay.RemoteMonitor/UserControls/ProcessListviewitem.cs @@ -113,4 +113,55 @@ namespace SiMay.RemoteMonitor.UserControls return describe; } } + + public class ServiceViewItem : ListViewItem + { + public string ServiceName { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + public string Status { get; set; } + public string UserName { get; set; } + public string StartType { get; set; } + public ServiceViewItem(string serviceName, string displayName, string description, string status, string startType, string userName) + { + this.ServiceName = serviceName; + this.DisplayName = displayName; + this.Description = description; + this.Status = status; + this.StartType = startType; + this.UserName = userName; + + this.Text = serviceName; + this.SubItems.Add(displayName); + this.SubItems.Add(description); + this.SubItems.Add(ServiceStatus(status)); + this.SubItems.Add(ServiceStatus(startType)); + this.SubItems.Add(userName); + } + + private string ServiceStatus(string status) + { + if (status == "Running") + { + return "正在运行"; + } + else if (status == "Stopped") + { + return "未在运行"; + } + else if (status == "Automatic") + { + return "自动"; + } + else if (status == "Manual") + { + return "手动"; + } + else if (status == "Disabled") + { + return "禁用"; + } + return "未知"; + } + } } -- Gitee From 3fad33052f11eb2f97968e7e4e8f623e2ddcaa9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=83=E7=82=B9=E5=B7=A5=E5=9D=8A?= Date: Wed, 18 Mar 2020 14:51:37 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E5=8D=B8?= =?UTF-8?q?=E8=BD=BD=E5=BA=94=E7=94=A8=E7=A8=8B=E5=BA=8F=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiMay.Core/MessageHead.cs | 3 + .../Packets/SysManager/SystemInfoPack.cs | 5 + .../Packets/SysManager/UninstallInfo.cs | 15 +++ SiMay.Core/SiMay.Core.csproj | 1 + .../ApplicationService/SystemService.cs | 91 +++++++++++++++++++ .../SystemAdapterHandler.cs | 18 ++++ .../Application/SystemApplication.Designer.cs | 84 +++++++++++++---- .../Application/SystemApplication.cs | 34 +++++++ .../Application/SystemApplication.resx | 3 + .../UserControls/ProcessListviewitem.cs | 17 ++++ 10 files changed, 254 insertions(+), 17 deletions(-) create mode 100644 SiMay.Core/Packets/SysManager/UninstallInfo.cs diff --git a/SiMay.Core/MessageHead.cs b/SiMay.Core/MessageHead.cs index 305df70..f16f879 100644 --- a/SiMay.Core/MessageHead.cs +++ b/SiMay.Core/MessageHead.cs @@ -121,6 +121,8 @@ namespace SiMay.Core S_SYSTEM_SERVICE_START, //启动服务 S_SYSTEM_SERVICE_RESTART, //重启服务 S_SYSTEM_SERVICE_STARTTYPE_SET, //设置服务启动方式 + S_SYSTEM_UNINSTALL_LIST, //安装程序列表 + S_SYSTEM_UNINSTALL_UN, //卸载程序 //接收指令 C_SYSTEM_PROCESS_LIST = 2000, //进程列表 @@ -128,6 +130,7 @@ namespace SiMay.Core C_SYSTEM_OCCUPY_INFO, //系统占用率信息 C_SYSTEM_SESSIONS, //会话信息 C_SYSTEM_SERVICE_LIST, //服务列表 + C_SYSTEM_UNINSTALL_LIST, //安装程序列表 //键盘记录--------------------------------------------------------------- S_KEYBOARD_ONOPEN = 1000, //窗口打开 diff --git a/SiMay.Core/Packets/SysManager/SystemInfoPack.cs b/SiMay.Core/Packets/SysManager/SystemInfoPack.cs index f2dbec2..338c94e 100644 --- a/SiMay.Core/Packets/SysManager/SystemInfoPack.cs +++ b/SiMay.Core/Packets/SysManager/SystemInfoPack.cs @@ -30,4 +30,9 @@ namespace SiMay.Core.Packets { public ServiceItem[] ServiceList { get; set; } } + + public class UninstallInfoPack : EntitySerializerBase + { + public UninstallInfo[] UninstallList { get; set; } + } } diff --git a/SiMay.Core/Packets/SysManager/UninstallInfo.cs b/SiMay.Core/Packets/SysManager/UninstallInfo.cs new file mode 100644 index 0000000..4d466cd --- /dev/null +++ b/SiMay.Core/Packets/SysManager/UninstallInfo.cs @@ -0,0 +1,15 @@ +namespace SiMay.Core.Packets +{ + public class UninstallInfo : ReflectCache.EntitySerializerBase + { + public string DisplayName { get; set; } + public string InstallLocation { get; set; } + public string UninstallString { get; set; } + public string ReleaseType { get; set; } + public string DisplayVersion { get; set; } + public string Publisher { get; set; } + public string InstallSource { get; set; } + public string Size { get; set; } + public string InstallDate { get; set; } + } +} diff --git a/SiMay.Core/SiMay.Core.csproj b/SiMay.Core/SiMay.Core.csproj index 42a241c..ff3900e 100644 --- a/SiMay.Core/SiMay.Core.csproj +++ b/SiMay.Core/SiMay.Core.csproj @@ -149,6 +149,7 @@ + diff --git a/SiMay.RemoteClient.NewCore/ApplicationService/SystemService.cs b/SiMay.RemoteClient.NewCore/ApplicationService/SystemService.cs index f419334..cd969e8 100644 --- a/SiMay.RemoteClient.NewCore/ApplicationService/SystemService.cs +++ b/SiMay.RemoteClient.NewCore/ApplicationService/SystemService.cs @@ -419,5 +419,96 @@ namespace SiMay.ServiceCore { return (string)Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + serviceName)?.GetValue("ImagePath") ?? string.Empty; } + + private void SendUninstallList() + { + SendTo(CurrentSession, MessageHead.C_SYSTEM_UNINSTALL_LIST, GetUninstallInfo()); + } + + [PacketHandler(MessageHead.S_SYSTEM_UNINSTALL_LIST)] + public void GetUninstallList(TcpSocketSaeaSession session) => this.SendUninstallList(); + + [PacketHandler(MessageHead.S_SYSTEM_UNINSTALL_UN)] + public void Uninstall_UN(TcpSocketSaeaSession session) + { + var uninstallItem = GetMessageEntity(session); + try + { + Process.Start(GetUninstallInfo(uninstallItem.DisplayName).UninstallList[0].UninstallString); + } + catch { } + SendUninstallList(); + + } + + private UninstallInfoPack GetUninstallInfo(string displayName = "") + { + var strRegPath = new string[] { + @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", + @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" + }; + var pack = new UninstallInfoPack(); + pack.UninstallList = new UninstallInfo[] { }; + foreach (var item in strRegPath) + { + RegistryKey regMainKey = Registry.LocalMachine.OpenSubKey(item); + foreach (string strMainKey in regMainKey.GetSubKeyNames()) + { + RegistryKey regCurrentKey = regMainKey.OpenSubKey(strMainKey); + object objDisplayName = regCurrentKey.GetValue("DisplayName"), + objInstallSource = regCurrentKey.GetValue("InstallSource"), + objUninstallString = regCurrentKey.GetValue("UninstallString"), + objInstallLocation = regCurrentKey.GetValue("InstallLocation"), + objPublisher = regCurrentKey.GetValue("Publisher"), + objDisplayVersion = regCurrentKey.GetValue("DisplayVersion"), + objReleaseType = regCurrentKey.GetValue("ReleaseType"), + objSize = regCurrentKey.GetValue("Size"), + objInstallDate = regCurrentKey.GetValue("InstallDate"); + if (objDisplayName != null && objUninstallString != null) + { + if (displayName == string.Empty) + { + var info = new UninstallInfo() + { + DisplayName = objDisplayName.ToString(), + InstallSource = objInstallSource == null ? string.Empty : objInstallSource.ToString(), + UninstallString = objUninstallString == null ? string.Empty : objUninstallString.ToString(), + InstallLocation = objInstallLocation == null ? string.Empty : objInstallLocation.ToString(), + Publisher = objPublisher == null ? string.Empty : objPublisher.ToString(), + DisplayVersion = objDisplayVersion == null ? string.Empty : objDisplayVersion.ToString(), + ReleaseType = objReleaseType == null ? string.Empty : objReleaseType.ToString(), + Size = objSize == null ? string.Empty : objSize.ToString(), + InstallDate = objInstallDate == null ? string.Empty : objInstallDate.ToString() + }; + List list = pack.UninstallList.ToList(); + list.Add(info); + pack.UninstallList = list.ToArray(); + } + else if (objDisplayName.ToString() == displayName) + { + var info = new UninstallInfo() + { + DisplayName = objDisplayName.ToString(), + InstallSource = objInstallSource == null ? string.Empty : objInstallSource.ToString(), + UninstallString = objUninstallString == null ? string.Empty : objUninstallString.ToString(), + InstallLocation = objInstallLocation == null ? string.Empty : objInstallLocation.ToString(), + Publisher = objPublisher == null ? string.Empty : objPublisher.ToString(), + DisplayVersion = objDisplayVersion == null ? string.Empty : objDisplayVersion.ToString(), + ReleaseType = objReleaseType == null ? string.Empty : objReleaseType.ToString(), + Size = objSize == null ? string.Empty : objSize.ToString(), + InstallDate = objInstallDate == null ? string.Empty : objInstallDate.ToString() + }; + List list = pack.UninstallList.ToList(); + list.Add(info); + pack.UninstallList = list.ToArray(); + return pack; + } + + } + + } + } + return pack; + } } } \ No newline at end of file diff --git a/SiMay.RemoteControlsCore/ApplicationAdapterHandlers/SystemAdapterHandler.cs b/SiMay.RemoteControlsCore/ApplicationAdapterHandlers/SystemAdapterHandler.cs index 7a36891..14aaf59 100644 --- a/SiMay.RemoteControlsCore/ApplicationAdapterHandlers/SystemAdapterHandler.cs +++ b/SiMay.RemoteControlsCore/ApplicationAdapterHandlers/SystemAdapterHandler.cs @@ -22,6 +22,9 @@ namespace SiMay.RemoteControlsCore.HandlerAdapters public event Action OnOccupyHandlerEvent; + public event Action> OnUninstallListEventHandler; + + [PacketHandler(MessageHead.C_SYSTEM_SYSTEMINFO)] private void HandlerProcessList(SessionProviderContext session) { @@ -136,5 +139,20 @@ namespace SiMay.RemoteControlsCore.HandlerAdapters { SendTo(CurrentSession, MessageHead.S_SYSTEM_SERVICE_STARTTYPE_SET, serviceItems); } + + [PacketHandler(MessageHead.C_SYSTEM_UNINSTALL_LIST)] + private void UninstallInfoHandler(SessionProviderContext session) + { + var uninstallList = GetMessageEntity(session).UninstallList; + OnUninstallListEventHandler?.Invoke(this, uninstallList); + } + public void Uninstall_GetList() + { + SendTo(CurrentSession, MessageHead.S_SYSTEM_UNINSTALL_LIST); + } + public void Uninstall_Un(UninstallInfo uninstallInfo) + { + SendTo(CurrentSession, MessageHead.S_SYSTEM_UNINSTALL_UN, uninstallInfo); + } } } diff --git a/SiMay.RemoteMonitor/Application/SystemApplication.Designer.cs b/SiMay.RemoteMonitor/Application/SystemApplication.Designer.cs index b164ba1..1c65f30 100644 --- a/SiMay.RemoteMonitor/Application/SystemApplication.Designer.cs +++ b/SiMay.RemoteMonitor/Application/SystemApplication.Designer.cs @@ -82,6 +82,10 @@ namespace SiMay.RemoteMonitor.Application this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel(); this.moryUse = new System.Windows.Forms.ToolStripStatusLabel(); this.refreshTimer = new System.Windows.Forms.Timer(this.components); + this.tabPage5 = new System.Windows.Forms.TabPage(); + this.UninstallList = new SiMay.RemoteMonitor.UserControls.UListView(); + this.cmunUninstall = new System.Windows.Forms.ContextMenuStrip(this.components); + this.tmunUninstall = new System.Windows.Forms.ToolStripMenuItem(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); this.tabPage3.SuspendLayout(); @@ -90,6 +94,8 @@ namespace SiMay.RemoteMonitor.Application this.munServiceList.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); + this.tabPage5.SuspendLayout(); + this.cmunUninstall.SuspendLayout(); this.SuspendLayout(); // // tabControl1 @@ -101,8 +107,9 @@ namespace SiMay.RemoteMonitor.Application this.tabControl1.Controls.Add(this.tabPage3); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Controls.Add(this.tabPage4); + this.tabControl1.Controls.Add(this.tabPage5); this.tabControl1.Location = new System.Drawing.Point(5, 23); - this.tabControl1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabControl1.Margin = new System.Windows.Forms.Padding(2); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(624, 435); @@ -116,9 +123,9 @@ namespace SiMay.RemoteMonitor.Application this.tabPage1.Controls.Add(this.button2); this.tabPage1.Controls.Add(this.processList); this.tabPage1.Location = new System.Drawing.Point(4, 22); - this.tabPage1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage1.Margin = new System.Windows.Forms.Padding(2); this.tabPage1.Name = "tabPage1"; - this.tabPage1.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage1.Padding = new System.Windows.Forms.Padding(2); this.tabPage1.Size = new System.Drawing.Size(616, 409); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "进程管理"; @@ -127,7 +134,7 @@ namespace SiMay.RemoteMonitor.Application // this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.button4.Location = new System.Drawing.Point(401, 387); - this.button4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.button4.Margin = new System.Windows.Forms.Padding(2); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(66, 19); this.button4.TabIndex = 14; @@ -139,7 +146,7 @@ namespace SiMay.RemoteMonitor.Application // this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.button3.Location = new System.Drawing.Point(472, 387); - this.button3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.button3.Margin = new System.Windows.Forms.Padding(2); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(66, 19); this.button3.TabIndex = 13; @@ -151,7 +158,7 @@ namespace SiMay.RemoteMonitor.Application // this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.button2.Location = new System.Drawing.Point(542, 387); - this.button2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.button2.Margin = new System.Windows.Forms.Padding(2); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(66, 19); this.button2.TabIndex = 12; @@ -169,7 +176,7 @@ namespace SiMay.RemoteMonitor.Application this.processList.FullRowSelect = true; this.processList.HideSelection = false; this.processList.Location = new System.Drawing.Point(10, 11); - this.processList.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.processList.Margin = new System.Windows.Forms.Padding(2); this.processList.Name = "processList"; this.processList.Size = new System.Drawing.Size(600, 373); this.processList.TabIndex = 11; @@ -182,9 +189,9 @@ namespace SiMay.RemoteMonitor.Application this.tabPage3.Controls.Add(this.button1); this.tabPage3.Controls.Add(this.sessionsListView); this.tabPage3.Location = new System.Drawing.Point(4, 22); - this.tabPage3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage3.Margin = new System.Windows.Forms.Padding(2); this.tabPage3.Name = "tabPage3"; - this.tabPage3.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage3.Padding = new System.Windows.Forms.Padding(2); this.tabPage3.Size = new System.Drawing.Size(616, 409); this.tabPage3.TabIndex = 2; this.tabPage3.Text = "会话管理"; @@ -194,7 +201,7 @@ namespace SiMay.RemoteMonitor.Application // this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.button1.Location = new System.Drawing.Point(542, 386); - this.button1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.button1.Margin = new System.Windows.Forms.Padding(2); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(66, 19); this.button1.TabIndex = 13; @@ -218,7 +225,7 @@ namespace SiMay.RemoteMonitor.Application this.sessionsListView.FullRowSelect = true; this.sessionsListView.HideSelection = false; this.sessionsListView.Location = new System.Drawing.Point(10, 11); - this.sessionsListView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.sessionsListView.Margin = new System.Windows.Forms.Padding(2); this.sessionsListView.Name = "sessionsListView"; this.sessionsListView.Size = new System.Drawing.Size(600, 371); this.sessionsListView.TabIndex = 12; @@ -256,9 +263,9 @@ namespace SiMay.RemoteMonitor.Application this.tabPage2.BackColor = System.Drawing.SystemColors.ButtonHighlight; this.tabPage2.Controls.Add(this.systemInfoList); this.tabPage2.Location = new System.Drawing.Point(4, 22); - this.tabPage2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage2.Margin = new System.Windows.Forms.Padding(2); this.tabPage2.Name = "tabPage2"; - this.tabPage2.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage2.Padding = new System.Windows.Forms.Padding(2); this.tabPage2.Size = new System.Drawing.Size(616, 409); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "系统信息"; @@ -276,7 +283,7 @@ namespace SiMay.RemoteMonitor.Application this.systemInfoList.FullRowSelect = true; this.systemInfoList.HideSelection = false; this.systemInfoList.Location = new System.Drawing.Point(4, 5); - this.systemInfoList.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.systemInfoList.Margin = new System.Windows.Forms.Padding(2); this.systemInfoList.Name = "systemInfoList"; this.systemInfoList.Size = new System.Drawing.Size(609, 407); this.systemInfoList.TabIndex = 12; @@ -298,9 +305,9 @@ namespace SiMay.RemoteMonitor.Application // this.tabPage4.Controls.Add(this.serviceList); this.tabPage4.Location = new System.Drawing.Point(4, 22); - this.tabPage4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage4.Margin = new System.Windows.Forms.Padding(2); this.tabPage4.Name = "tabPage4"; - this.tabPage4.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tabPage4.Padding = new System.Windows.Forms.Padding(2); this.tabPage4.Size = new System.Drawing.Size(616, 409); this.tabPage4.TabIndex = 3; this.tabPage4.Text = "服务信息"; @@ -320,7 +327,7 @@ namespace SiMay.RemoteMonitor.Application this.serviceList.FullRowSelect = true; this.serviceList.HideSelection = false; this.serviceList.Location = new System.Drawing.Point(2, 2); - this.serviceList.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.serviceList.Margin = new System.Windows.Forms.Padding(2); this.serviceList.Name = "serviceList"; this.serviceList.Size = new System.Drawing.Size(612, 405); this.serviceList.TabIndex = 0; @@ -558,6 +565,43 @@ namespace SiMay.RemoteMonitor.Application this.refreshTimer.Interval = 1500; this.refreshTimer.Tick += new System.EventHandler(this.RefreshTimer_Tick); // + // tabPage5 + // + this.tabPage5.Controls.Add(this.UninstallList); + this.tabPage5.Location = new System.Drawing.Point(4, 22); + this.tabPage5.Name = "tabPage5"; + this.tabPage5.Size = new System.Drawing.Size(616, 409); + this.tabPage5.TabIndex = 4; + this.tabPage5.Text = "程序信息"; + this.tabPage5.UseVisualStyleBackColor = true; + // + // UninstallList + // + this.UninstallList.ContextMenuStrip = this.cmunUninstall; + this.UninstallList.Dock = System.Windows.Forms.DockStyle.Fill; + this.UninstallList.FullRowSelect = true; + this.UninstallList.HideSelection = false; + this.UninstallList.Location = new System.Drawing.Point(0, 0); + this.UninstallList.Name = "UninstallList"; + this.UninstallList.Size = new System.Drawing.Size(616, 409); + this.UninstallList.TabIndex = 0; + this.UninstallList.UseCompatibleStateImageBehavior = false; + this.UninstallList.UseWindowsThemStyle = true; + this.UninstallList.View = System.Windows.Forms.View.Details; + // + // cmunUninstall + // + this.cmunUninstall.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.tmunUninstall}); + this.cmunUninstall.Name = "cmunUninstall"; + this.cmunUninstall.Size = new System.Drawing.Size(101, 26); + // + // tmunUninstall + // + this.tmunUninstall.Name = "tmunUninstall"; + this.tmunUninstall.Size = new System.Drawing.Size(100, 22); + this.tmunUninstall.Text = "卸载"; + // // SystemApplication // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -582,6 +626,8 @@ namespace SiMay.RemoteMonitor.Application this.menuStrip1.PerformLayout(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); + this.tabPage5.ResumeLayout(false); + this.cmunUninstall.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -640,5 +686,9 @@ namespace SiMay.RemoteMonitor.Application private System.Windows.Forms.ToolStripMenuItem tmunAutomatic; private System.Windows.Forms.ToolStripMenuItem tmunManual; private System.Windows.Forms.ToolStripMenuItem tmunDisable; + private System.Windows.Forms.TabPage tabPage5; + private UListView UninstallList; + private System.Windows.Forms.ContextMenuStrip cmunUninstall; + private System.Windows.Forms.ToolStripMenuItem tmunUninstall; } } \ No newline at end of file diff --git a/SiMay.RemoteMonitor/Application/SystemApplication.cs b/SiMay.RemoteMonitor/Application/SystemApplication.cs index 630ea65..f0a667a 100644 --- a/SiMay.RemoteMonitor/Application/SystemApplication.cs +++ b/SiMay.RemoteMonitor/Application/SystemApplication.cs @@ -62,10 +62,17 @@ namespace SiMay.RemoteMonitor.Application this.processList.Columns.Add("用户名称", 100); this.processList.Columns.Add("文件位置", 300); + this.UninstallList.Columns.Add("名称", 150); + this.UninstallList.Columns.Add("发布者", 150); + this.UninstallList.Columns.Add("安装时间", 100); + this.UninstallList.Columns.Add("大小", 100); + this.UninstallList.Columns.Add("版本", 100); + this.SystemAdapterHandler.OnProcessListHandlerEvent += OnProcessListHandlerEvent; this.SystemAdapterHandler.OnSystemInfoHandlerEvent += OnSystemInfoHandlerEvent; this.SystemAdapterHandler.OnOccupyHandlerEvent += OnOccupyHandlerEvent; this.SystemAdapterHandler.OnSessionsEventHandler += OnSessionsEventHandler; + this.SystemAdapterHandler.OnUninstallListEventHandler += OnUninstallListEventHandler; this._title = _title.Replace("#Name#", SystemAdapterHandler.OriginName); this.Text = this._title; this.SystemAdapterHandler.GetSystemInfoItems(); @@ -74,6 +81,19 @@ namespace SiMay.RemoteMonitor.Application this.SystemAdapterHandler.OnServicesListEventHandler += OnServicesListEventHandler; this.SystemAdapterHandler.Service_GetList(); + this.SystemAdapterHandler.Uninstall_GetList(); + } + + + private void OnUninstallListEventHandler(SystemAdapterHandler adapterHandler, IEnumerable uninstalllInfo) + { + this.UninstallList.Items.Clear(); + var uninstalllList = new List(uninstalllInfo); + foreach (var item in uninstalllList) + { + var uninstalllItem = new UninstallViewItem(item.DisplayName, item.Publisher, item.InstallDate, item.Size, item.DisplayVersion); + this.UninstallList.Items.Add(uninstalllItem); + } } private void OnSessionsEventHandler(SystemAdapterHandler adapterHandler, IEnumerable sessions) @@ -156,6 +176,8 @@ namespace SiMay.RemoteMonitor.Application this.SystemAdapterHandler.OnSystemInfoHandlerEvent -= OnSystemInfoHandlerEvent; this.SystemAdapterHandler.OnOccupyHandlerEvent -= OnOccupyHandlerEvent; this.SystemAdapterHandler.OnSessionsEventHandler -= OnSessionsEventHandler; + this.SystemAdapterHandler.OnServicesListEventHandler -= OnServicesListEventHandler; + this.SystemAdapterHandler.OnUninstallListEventHandler -= OnUninstallListEventHandler; this.SystemAdapterHandler.CloseSession(); } @@ -386,5 +408,17 @@ namespace SiMay.RemoteMonitor.Application }); } } + + private void tmunUninstall_Click(object sender, EventArgs e) + { + if (UninstallList.SelectedItems.Count > 0) + { + ListView.SelectedListViewItemCollection selectItem = this.UninstallList.SelectedItems; + this.SystemAdapterHandler.Uninstall_Un(new UninstallInfo() + { + DisplayName = selectItem[0].Text + }); + } + } } } \ No newline at end of file diff --git a/SiMay.RemoteMonitor/Application/SystemApplication.resx b/SiMay.RemoteMonitor/Application/SystemApplication.resx index 2ff891c..23dbb6e 100644 --- a/SiMay.RemoteMonitor/Application/SystemApplication.resx +++ b/SiMay.RemoteMonitor/Application/SystemApplication.resx @@ -120,6 +120,9 @@ 17, 17 + + 524, 17 + 157, 17 diff --git a/SiMay.RemoteMonitor/UserControls/ProcessListviewitem.cs b/SiMay.RemoteMonitor/UserControls/ProcessListviewitem.cs index 55c2fc2..a22da2f 100644 --- a/SiMay.RemoteMonitor/UserControls/ProcessListviewitem.cs +++ b/SiMay.RemoteMonitor/UserControls/ProcessListviewitem.cs @@ -164,4 +164,21 @@ namespace SiMay.RemoteMonitor.UserControls return "未知"; } } + + public class UninstallViewItem : ListViewItem + { + public UninstallViewItem(string displayName, string publisher, string installDate, string size, string displayVersion) + { + try + { + this.Text = displayName; + this.SubItems.Add(publisher); + this.SubItems.Add(DateTime.TryParse(installDate, out DateTime dt) ? DateTime.Parse(installDate).ToShortDateString() : DateTime.ParseExact(installDate, "yyyyMMdd", System.Threading.Thread.CurrentThread.CurrentCulture).ToShortDateString()); + this.SubItems.Add(size); + this.SubItems.Add(displayVersion); + } + catch { } + + } + } } -- Gitee From ac786f2dbd64e7c6f879ce9db5d28c8e451a783b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=83=E7=82=B9=E5=B7=A5=E5=9D=8A?= Date: Wed, 1 Apr 2020 16:10:49 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=94=A8=E6=88=B7=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E7=AA=97=E4=BD=93=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiMay.Core/Packets/UserFolder.cs | 17 ++++ SiMay.Core/SiMay.Core.csproj | 1 + .../ApplicationService/FileService.cs | 89 ++++++++++++++++++- 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 SiMay.Core/Packets/UserFolder.cs diff --git a/SiMay.Core/Packets/UserFolder.cs b/SiMay.Core/Packets/UserFolder.cs new file mode 100644 index 0000000..66fbc95 --- /dev/null +++ b/SiMay.Core/Packets/UserFolder.cs @@ -0,0 +1,17 @@ +using SiMay.ReflectCache; + +namespace SiMay.Core.Packets +{ + public class UserFolder : EntitySerializerBase + { + public string UserName { get; set; } + public string USID { get; set; } + public UserShellFolders[] UserShellFolders { get; set; } + } + + public class UserShellFolders : EntitySerializerBase + { + public string Name { get; set; } + public string Path { get; set; } + } +} diff --git a/SiMay.Core/SiMay.Core.csproj b/SiMay.Core/SiMay.Core.csproj index 42a241c..28ea631 100644 --- a/SiMay.Core/SiMay.Core.csproj +++ b/SiMay.Core/SiMay.Core.csproj @@ -151,6 +151,7 @@ + diff --git a/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs b/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs index 6f0e1c7..088f129 100644 --- a/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs +++ b/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs @@ -1,4 +1,5 @@ -using SiMay.Basic; +using Microsoft.Win32; +using SiMay.Basic; using SiMay.Core; using SiMay.Core.Common; using SiMay.Core.Enums; @@ -481,6 +482,55 @@ namespace SiMay.ServiceCore public void RedirtionHandler(TcpSocketSaeaSession session) { var pack = GetMessageEntity(session); + var sessions = UserTrunkContext.UserTrunkContextInstance.GetSessionItems() + .Select(c => new SiMay.Core.Packets.SysManager.SessionItem() + { + UserName = c.UserName, + SessionId = c.SessionId, + SessionState = c.SessionState, + WindowStationName = c.WindowStationName, + HasUserProcess = c.HasUserProcess + }) + .ToArray(); + foreach (var sessionItem in sessions) + { + if (sessionItem.SessionState == 1 && sessionItem.UserName.ToLower() != "system") + { + List userFolders = GetUserFolderPath(); + foreach (var item in userFolders) + { + if (item.UserName == sessionItem.UserName) + { + string strFolderName = "Desktop"; + if (pack.SpecialFolder == Environment.SpecialFolder.MyDocuments) + { + strFolderName = "Personal"; + } + else if (pack.SpecialFolder == Environment.SpecialFolder.MyMusic) + { + strFolderName = "My Music"; + } + else if (pack.SpecialFolder == Environment.SpecialFolder.MyPictures) + { + strFolderName = "My Pictures"; + } + else if (pack.SpecialFolder == Environment.SpecialFolder.MyVideos) + { + strFolderName = "My Video"; + } + List userShellFolders = item.UserShellFolders.ToList(); + foreach (var usfItem in userShellFolders) + { + if (usfItem.Name == strFolderName) + { + this.GetFileListHandler(usfItem.Path); + return; + } + } + } + } + } + } this.GetFileListHandler(Environment.GetFolderPath(pack.SpecialFolder)); } @@ -660,5 +710,42 @@ namespace SiMay.ServiceCore return fileLst; } + + public static List GetUserFolderPath() + { + var userFolder = new List(); + using (RegistryKey regBaseKey = RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry32)) + { + foreach (string strUserKey in regBaseKey.GetSubKeyNames()) + { + if (strUserKey.ToLower().StartsWith("s-1-5-21") && !strUserKey.ToLower().Contains("classes")) + { + RegistryKey regUserKey = regBaseKey.OpenSubKey(strUserKey); + RegistryKey regEnvironment = regUserKey.OpenSubKey("Volatile Environment"); + string strUserName = (string)regEnvironment.GetValue("USERNAME", string.Empty); + if (strUserName != string.Empty) + { + RegistryKey regShellFolders = regUserKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"); + var userShellFolders = new List(); + foreach (string strKeyName in regShellFolders.GetValueNames()) + { + userShellFolders.Add(new UserShellFolders() + { + Name = strKeyName, + Path = (string)regShellFolders.GetValue(strKeyName, string.Empty) + }); + } + userFolder.Add(new UserFolder() + { + UserName = strUserName, + USID = strUserKey, + UserShellFolders = userShellFolders.ToArray() + }); + } + } + } + } + return userFolder; + } } } \ No newline at end of file -- Gitee From 180080adbb4b90903e351e41c3c9c5c3f575deda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=83=E7=82=B9=E5=B7=A5=E5=9D=8A?= Date: Sat, 4 Apr 2020 09:19:39 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=86=99=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs b/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs index 088f129..577ffac 100644 --- a/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs +++ b/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs @@ -494,7 +494,7 @@ namespace SiMay.ServiceCore .ToArray(); foreach (var sessionItem in sessions) { - if (sessionItem.SessionState == 1 && sessionItem.UserName.ToLower() != "system") + if (sessionItem.HasUserProcess && sessionItem.UserName.ToLower() != "system") { List userFolders = GetUserFolderPath(); foreach (var item in userFolders) -- Gitee From 45a42aebf7e95e4341f2ec033c5bbe41f6489546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=83=E7=82=B9=E5=B7=A5=E5=9D=8A?= Date: Sat, 4 Apr 2020 18:42:21 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApplicationService/FileService.cs | 120 +++++++++++------- 1 file changed, 71 insertions(+), 49 deletions(-) diff --git a/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs b/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs index 577ffac..5afb650 100644 --- a/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs +++ b/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs @@ -482,55 +482,25 @@ namespace SiMay.ServiceCore public void RedirtionHandler(TcpSocketSaeaSession session) { var pack = GetMessageEntity(session); - var sessions = UserTrunkContext.UserTrunkContextInstance.GetSessionItems() - .Select(c => new SiMay.Core.Packets.SysManager.SessionItem() - { - UserName = c.UserName, - SessionId = c.SessionId, - SessionState = c.SessionState, - WindowStationName = c.WindowStationName, - HasUserProcess = c.HasUserProcess - }) - .ToArray(); - foreach (var sessionItem in sessions) - { - if (sessionItem.HasUserProcess && sessionItem.UserName.ToLower() != "system") - { - List userFolders = GetUserFolderPath(); - foreach (var item in userFolders) - { - if (item.UserName == sessionItem.UserName) - { - string strFolderName = "Desktop"; - if (pack.SpecialFolder == Environment.SpecialFolder.MyDocuments) - { - strFolderName = "Personal"; - } - else if (pack.SpecialFolder == Environment.SpecialFolder.MyMusic) - { - strFolderName = "My Music"; - } - else if (pack.SpecialFolder == Environment.SpecialFolder.MyPictures) - { - strFolderName = "My Pictures"; - } - else if (pack.SpecialFolder == Environment.SpecialFolder.MyVideos) - { - strFolderName = "My Video"; - } - List userShellFolders = item.UserShellFolders.ToList(); - foreach (var usfItem in userShellFolders) - { - if (usfItem.Name == strFolderName) - { - this.GetFileListHandler(usfItem.Path); - return; - } - } - } - } - } + try + { + var userShellFolderPath = GetUserFolderPath() + .Where(c => c.UserName == UserTrunkContext.UserTrunkContextInstance.GetSessionItems() + .Select(c => new Core.Packets.SysManager.SessionItem() + { + UserName = c.UserName, + HasUserProcess = c.HasUserProcess + }) + .Where(c => c.HasUserProcess == true && c.UserName.ToLower() != "system") + .ToArray()[0].UserName) + .ToArray()[0].UserShellFolders + .Where(s => s.Name == FolderName(pack.SpecialFolder)) + .ToArray()[0].Path; + + this.GetFileListHandler(userShellFolderPath); + return; } + catch (Exception ex) { LogHelper.WriteErrorByCurrentMethod(ex); } this.GetFileListHandler(Environment.GetFolderPath(pack.SpecialFolder)); } @@ -710,7 +680,59 @@ namespace SiMay.ServiceCore return fileLst; } - + public static string FolderName(Environment.SpecialFolder specialFolder) + { + return specialFolder switch + { + Environment.SpecialFolder.ApplicationData => "AppData", + Environment.SpecialFolder.CommonApplicationData => "", + Environment.SpecialFolder.LocalApplicationData => "Local AppData", + Environment.SpecialFolder.Cookies => "Cookies", + Environment.SpecialFolder.Desktop => "Desktop", + Environment.SpecialFolder.Favorites => "Favorites", + Environment.SpecialFolder.History => "History", + Environment.SpecialFolder.InternetCache => "Cache", + Environment.SpecialFolder.Programs => "", + Environment.SpecialFolder.MyComputer => "", + Environment.SpecialFolder.MyMusic => "My Music", + Environment.SpecialFolder.MyPictures => "My Pictures", + Environment.SpecialFolder.MyVideos => "My Video", + Environment.SpecialFolder.Recent => "Recent", + Environment.SpecialFolder.SendTo => "SendTo", + Environment.SpecialFolder.StartMenu => "Start Menu", + Environment.SpecialFolder.Startup => "Startup", + Environment.SpecialFolder.System => "", + Environment.SpecialFolder.Templates => "Templates", + Environment.SpecialFolder.DesktopDirectory => "Desktop", + Environment.SpecialFolder.MyDocuments => "Personal", + Environment.SpecialFolder.ProgramFiles => "", + Environment.SpecialFolder.CommonProgramFiles => "", + Environment.SpecialFolder.AdminTools => "", + Environment.SpecialFolder.CDBurning => "", + Environment.SpecialFolder.CommonAdminTools => "", + Environment.SpecialFolder.CommonDocuments => "", + Environment.SpecialFolder.CommonMusic => "", + Environment.SpecialFolder.CommonOemLinks => "", + Environment.SpecialFolder.CommonPictures => "", + Environment.SpecialFolder.CommonStartMenu => "", + Environment.SpecialFolder.CommonPrograms => "", + Environment.SpecialFolder.CommonStartup => "", + Environment.SpecialFolder.CommonDesktopDirectory => "", + Environment.SpecialFolder.CommonTemplates => "", + Environment.SpecialFolder.CommonVideos => "", + Environment.SpecialFolder.Fonts => "", + Environment.SpecialFolder.NetworkShortcuts => "", + Environment.SpecialFolder.PrinterShortcuts => "", + Environment.SpecialFolder.UserProfile => "", + Environment.SpecialFolder.CommonProgramFilesX86 => "", + Environment.SpecialFolder.ProgramFilesX86 => "", + Environment.SpecialFolder.Resources => "", + Environment.SpecialFolder.LocalizedResources => "", + Environment.SpecialFolder.SystemX86 => "", + Environment.SpecialFolder.Windows => "", + _ => "", + }; + } public static List GetUserFolderPath() { var userFolder = new List(); -- Gitee