我需要检查“服务器”服务是否正在运行。很简单,使用这样的方法:How can I verify if a Windows Service is running
当操作系统安装不是英文时就会出现问题。例如,在 Windows 安装中,“Server”服务称为“Serveur”。显然我不想将不同的语言硬编码到我的应用程序中。任何人有干净地做这件事的好主意吗?
最佳答案
测试下面的代码,看看你得到什么结果,你可能会惊讶......
using System.ServiceProcess;
var controller = new ServiceController("LanmanServer");
Console.WriteLine(controller.ServiceName); // <- this is the unique name
Console.WriteLine(controller.DisplayName); // <- this is subject to change
关于c# - 检查 "Server"服务是否正在运行 - 多语言 C#.Net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5260283/