C# Query Windows Service

南笙酒味 提交于 2019-12-04 13:46:36

The information you're looking for is available in WMI.

It will be MUCH easier to write this whole thing in PowerShell than in Pure C#. WMI code gets very messy in C# (or C++, or VBScript), very quickly. This snippet demostrates getting the data from a list of computers. To embed in C#, simply use System.Management.Automation, and add PowerShell.Create().AddScript(...).Invoke()

$computerList = "a","b","c"
Get-WmiObject -computerName $computerList -asjob
    | Wait-job
    | receive-job
    | Select-Object DisplayName, Description, StartMode, State

Hope this helps,

Matt

The same code above worked. Just add this to Management Class

(@"\\" + serverIP + "\\root\\cimv2:Win32_Service")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!