WMI012-WMI學習筆記(十二)——Win32_ApplicationService

獲取的過程很慢,讓人有種卡死了的感覺。。。

運行結果截圖:


測試代碼:

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);
            }
        }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章