我需要在Windows Server上自动启动的服务。 有人可以告诉我一种使用WMI获取Windows Server状态(联机或脱机)的方法。在C#中使用WMI获取Windows服务器状态
预先感谢您
我需要在Windows Server上自动启动的服务。 有人可以告诉我一种使用WMI获取Windows Server状态(联机或脱机)的方法。在C#中使用WMI获取Windows服务器状态
预先感谢您
请尝试以下代码,
string FullComputerName = "<Name of Remote Computer>";
ConnectionOptions options = new ConnectionOptions();
ManagementScope scope = new ManagementScope("\\\\" + FullComputerName + "\\root\\cimv2", options);
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_TerminalService");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject queryObj in queryCollection)
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_TerminalService instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Started: {0}", queryObj["Started"]);
Console.WriteLine("State: {0}", queryObj["State"]);
Console.WriteLine("Status: {0}", queryObj["Status"]);
}
我从来没有做过这样的事情。我想连接到我的Windows Server上的Hyper-V群集。我需要写什么来做这件事? –
检查这里的完整的例子https://msdn.microsoft.com/en-us/ library/mt703458(v = vs.85).aspx –