C#小技巧系列之二:获取系统所有服务信息
2007-05-07 22:00
417 查看
说明:本人准备写一些C#有关的小技巧系列文章,这些文章含金量并不高,代码难度不大,不过因为问的次数比较多,从而导致本人决定用自己所知的方式写这一系列文章,可以看做“趣味导学”系列吧。
这是一个获取系统所有服务的程序,为了简化程序,代码仍以控制台形式提供,大家可以另外封装自己希望的功能。
核心代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceProcess;
namespace Study
...{
public class ServiceInfo
...{
public void ShowServiceInfo()
...{
ServiceController[] services=System.ServiceProcess.ServiceController.GetServices();
System.Console.WriteLine("Service名称 Service显示名称 Service状态");
for (int i = 0; i < services.Length; i++)
...{
System.Console.WriteLine(string.Format("{0} {1} {2}", services[i].ServiceName, services[i].DisplayName, services[i].Status.ToString()));
}
}
}
}
启动代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace Study
...{
class Program
...{
static void Main(string[] args)
...{
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.ShowServiceInfo();
Console.ReadLine();
}
}
}
本文出自 “周公(周金桥)的专栏” 博客,请务必保留此出处http://zhoufoxcn.blog.51cto.com/792419/164401
这是一个获取系统所有服务的程序,为了简化程序,代码仍以控制台形式提供,大家可以另外封装自己希望的功能。
核心代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceProcess;
namespace Study
...{
public class ServiceInfo
...{
public void ShowServiceInfo()
...{
ServiceController[] services=System.ServiceProcess.ServiceController.GetServices();
System.Console.WriteLine("Service名称 Service显示名称 Service状态");
for (int i = 0; i < services.Length; i++)
...{
System.Console.WriteLine(string.Format("{0} {1} {2}", services[i].ServiceName, services[i].DisplayName, services[i].Status.ToString()));
}
}
}
}
启动代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace Study
...{
class Program
...{
static void Main(string[] args)
...{
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.ShowServiceInfo();
Console.ReadLine();
}
}
}
本文出自 “周公(周金桥)的专栏” 博客,请务必保留此出处http://zhoufoxcn.blog.51cto.com/792419/164401
相关文章推荐
- C#小技巧系列之二:获取系统所有服务信息
- C#小技巧系列之二:获取系统所有服务信息
- C#小技巧系列之一:获取系统有关信息
- C#小技巧系列之一:获取系统有关信息
- C#小技巧系列之三:获取系统进程信息
- C#小技巧系列之三:获取系统进程信息
- C#小技巧系列之三:获取系统进程信息
- 通过VBS 获取系统所有服务信息
- C#小技巧系列之四:获取本地网络信息
- C#小技巧系列之四:获取本地网络信息
- C#小技巧系列之四:获取本地网络信息
- 在C#中如何获取系统中所安装的所有软件信息,还有如何打开系统中某个程序
- C#递归获取所有目录下的文件信息并生成对应的XML件
- C#获取当前系统信息的类
- Android系统信息获取 之二:版本信息获取
- 获取系统运行的所有进程的信息
- C#获取IIS所有站点及虚拟目录和应用程序(包含名称及详细信息)
- C#: 抓取网页类(获取网页中所有信息)
- C#获取系统版本信息
- 转:C# 获取指定目录下所有文件信息、移动目录、拷贝目录