在我们的应用程序中,我们想要确定 iis 是否安装在机器中。如果已安装,那么我们需要确定它是否正在运行。
有什么方法可以获取这些详细信息。
最佳答案
Using Managed Code to Detect if IIS is Installed and ASP/ASP.NET is Registered
IIS 是否运行检查下面的代码
只需将“System.ServiceProcess”的引用添加到您的项目。
ServiceController sc = new ServiceController("World Wide Web Publishing Service");
if ((sc.Status.Equals(ServiceControllerStatus.Stopped) || sc.Status.Equals(ServiceControllerStatus.StopPending))) {
Console.WriteLine("Starting the service...");
sc.Start();
}
else {
Console.WriteLine("Stopping the service...");
sc.Stop();
}
关于c# - 检查 IIS 是否已安装并正在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9816751/