2012-03-22 72 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

相關問題