在 C# 中使用 WMI 获取 Windows 服务器状态

Get Windows Server status using WMI in C#

我需要在 Windows 服务器上自动启动的服务。 谁能告诉我一种使用 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"]);
            }

来源:- https://social.msdn.microsoft.com/Forums/vstudio/en-US/a25d3071-2283-41c6-9262-6860d7965963/how-to-check-remote-servers-terminal-status-using-c?forum=csharpgeneral