获取的过程很慢,让人有种卡死了的感觉。。。
运行结果截图:
测试代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management.Instrumentation;
using System.Management;
using System.Reflection;
namespace Eyuan.WMIStudy.Win32
{
public partial class fmApplicationService : Form
{
#region Win32_ApplicationService属性名称
private enum EApplicationServicePropertyName : byte
{
Caption,
CreationClassName,
Description,
InstallDate,
Name,
Started,
StartMode,
Status,
SystemCreationClassName,
SystemName
}
#endregion
public fmApplicationService()
{
InitializeComponent();
}
#region 类字段
private StringBuilder sbApplicationServiceInfo = new StringBuilder();
private string strSql = string.Empty;
private int iMOCount;
#endregion
/// <summary>
/// 窗体加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void fmApplicationService_Load(object sender, EventArgs e)
{
strSql = "SELECT * FROM Win32_ApplicationService";
ManagementObjectSearcher search = new ManagementObjectSearcher(strSql);
iMOCount = 0;
//
foreach (ManagementObject mo in search.Get())
{
sbApplicationServiceInfo.AppendLine("第" + (++iMOCount) + "个ApplicationService:");
foreach (string moName in Enum.GetNames(typeof(EApplicationServicePropertyName)))
{
sbApplicationServiceInfo.AppendFormat("{0,-20}:{1}\n", moName, mo[moName]);
}
}
//
foreach (string strAccountInfo in sbApplicationServiceInfo.ToString().Split(new string[] { "\n" }, StringSplitOptions.None))
{
lbApplicationServiceInfo.Items.Add(strAccountInfo);
}
}
}
}