1、using System.Windows.Forms。using Microsoft.Win32。using System.IO。using System.ServiceProcess。using System.Diagnostics。3.刷新服务功能的实现private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e lstserver.Items.Clear(。 #region 刷新服务 watch = System.ServiceProcess.ServiceController.GetServices( foreach
2、 (ServiceController temp in watch try string servepath = ListViewItem lv = new ListViewItem(temp.DisplayName.ToString( lv.SubItems.Add(temp.ServiceName.ToString( #region 1.服务状态 if (temp.Status.ToString( = Stopped lv.SubItems.Add(已停止 else if (temp.Status.ToString(Running正在运行 else已暂停 #endregion #regio
3、n 2.服务启动类型 RegistryKey hklmrun1 = Registry.LocalMachine。 RegistryKey hklmrun2 = hklmrun1.CreateSubKey(systemcurrentcontrolsetservices + temp.ServiceName.ToString( string regs = hklmrun2.GetValue(start.ToString( if (regs = 3手动 else if (regs = 4已禁用2 自动0未知 catch #region 3.服务描述 RegistryKey hklmrun2= hkl
4、mrun1.CreateSubKey(Description lv.SubItems.Add(regs #region 4.服务路径 servepath = hklmrun2.GetValue(ImagePath lv.SubItems.Add(servepath #region 5.服务厂商 string fileinfo = FileVersionInfo finfo = FileVersionInfo.GetVersionInfo(servepath fileinfo = finfo.CompanyName。 lv.SubItems.Add(fileinfo if (fileinfo !
5、= Microsoft Corporation&fileinfo != lv.ForeColor = Color.Blue。 lstserver.Items.Add(lv lblservecount.Text = 当前服务: + lstserver.Items.Count.ToString( + 项4.显示已启动服务功能的实现private void 显示已启动服务ToolStripMenuItem_Click(object sender, EventArgs e #region foreach string serverrunning = serverrunning = temp.Statu
6、s.ToString( if (serverrunning = ListViewItem lv=new ListViewItem(temp.DisplayName.ToString(RegistryKey hklmrun2 = hklmrun1.CreateSubKey( | regs = & fileinfo !5.显示未启动服务功能的实现private void 显示未启动服务ToolStripMenuItem_Click(object sender, EventArgs e if (serverrunning !6.显示自动启动服务功能的实现private void 显示自动启动服务ToolStripMenuItem_Click(object sender, EventArgs e RegistryKey hklmrun11 = Registry.LocalMachine。RegistryKey hklmrun21 = hklmrun11.CreateSubKey( string serverrunning = hklmrun21.GetValue( | serverrunning = ls
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1