2012-03-22 77 views
1

在我们的应用程序中,我们要确定iis是否安装在机器中。如果安装,那么我们需要确定它是否在运行。检查IIS已安装并正在运行

有什么办法可以得到这个细节。

回答

7

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(); 
} 
+0

服务名称“W3SV”是否与iis5.0,iis6.0等所有iis一样? – 2012-03-22 05:19:28

+0

@mahesh - 不确定是否需要运行并检查。 – 2012-03-22 05:20:28

+0

使用“万维网发布”时,我的系统崩溃了。附加'服务',让它工作。它也适用于'W3SVC' – 2013-09-04 14:29:24

相关问题