我在C#和PowerShell上运行此WQL“SELECT * FROM Win32_Service WHERE Started = true”,但返回的结果不同。通过C#进行查询时,列表中找不到某些处于运行模式的服务。
C#代码:
ManagementObjectSearcher s1 = new ManagementObjectSearcher("SELECT * FROM Win32_Service WHERE Started=true");
ManagementObjectCollection qCollection = s1.Get();
foreach (ManagementObject mo in qCollection)
{
Console.WriteLine("Service: '{0}'", mo["Name"]);
}
PowerShell代码:
$query = "SELECT * FROM Win32_Service WHERE Started=true"
$results = Get-WmiObject -Query $query
$results|Export-Csv -path .\temp\service.csv -Encoding ASCII -NoTypeInformation