检查IIS是否已安装并正在运行

Mah*_* KP 2 c# asp.net iis

在我们的应用程序中,我们想要确定iis是否安装在计算机中.如果已安装,那么我们需要确定它是否正在运行.

有没有办法得到这个细节.

Pra*_*ana 10

使用托管代码检测IIS是否已安装且ASP/ASP.NET是否已注册

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();
}
Run Code Online (Sandbox Code Playgroud)