我需要检查,看看“服务器”服务是否正在运行。 很简单,使用这样的方法: 如何validationWindows服务是否正在运行
当操作系统安装不是英文时,问题就出现了。 例如,在Windows安装中,“服务器”服务被称为“服务器”。 显然,我不想单独的语言硬编码到我的应用程序。 任何人有任何好的想法,干净这样做?
测试下面的代码,看看你得到了什么结果,你可能会感到惊讶…
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
像其他人一样,我怀疑服务名称不会跨语言更改。 这通常是显示名称的变化。