我需要在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 –