Check to see if "Server" service is running - Multilingual C#.Net
I need to check and see if the "Server" service is running. Easy enough, using a method like this: How can I verify if a Windows Service is running
The problem comes in when the OS installation is not English. For example on a 开发者_StackOverflowWindows installation, the "Server" service is known as "Serveur". Obviously I don't want to hardcode separate languages into my app. Anyone have any good ideas for doing this cleanly?
Test out the following code and see what results you get, you may be surprised...
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
Like the others, I suspect that the service name doesn't change across languages. It's usually the display name that changes.
精彩评论