2009-10-27 75 views

回答

13

這是我知道的唯一途徑,我發現它環顧四周,測試它,它的工作原理。請確保您使用的服務名稱不是它的顯示名稱,您還需要添加一個引用到System.Management

string serviceName = "aspnet_state"; 

SelectQuery query = new System.Management.SelectQuery(string.Format(
    "select name, startname from Win32_Service where name = '{0}'", serviceName)); 
using (ManagementObjectSearcher searcher = 
    new System.Management.ManagementObjectSearcher(query)) 
{ 
    foreach (ManagementObject service in searcher.Get()) 
    { 
     Console.WriteLine(string.Format(
      "Name: {0} - Logon : {1} ", service["Name"], service["startname"])); 
    } 
} 
0

這將做你的工作

Get-WMIObject Win32_Service | Where-Object {$_.startname -ne "localSystem" }| Where-Object {$_.startname -ne "NT AUTHORITY\LocalService" } |Where-Object {$_.startname -ne "NT AUTHORITY\NetworkService" } |select startname, name 
相關問題