c# - 检查 "Server"服务是否正在运行 - 多语言 C#.Net

标签 c# .net windows service

我需要检查“服务器”服务是否正在运行。很简单,使用这样的方法: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/

相关文章:

.net - 在LINQPad中,您可以使用LINQ访问SYSOBJECTS吗?

css - IE11 中的粗体看起来与 chrome 中的粗体明显不同——这可以补救吗?

C#:通过方法在构造函数中设置属性

c# - 应用程序时间的设计模式?

c# - 任务 ContinueWith() 不更新 UI 线程上的光标

c# - 在 List<string> 中搜索字符串 .StartsWith()

.net - mac/linux `dotnet build` 找不到框架 ".NETFramework.."的引用程序集

.net - SQL Server Management Studio 是否随 Visual Studio 一起提供?

PHPMailer 在发送电子邮件时使用 Gmail SMTP 速度很慢

c++ - LoadLibrary 失败并出现错误 203 : The system could not find the environment option that was entered