我的iis應用程序池動不動就被自動停止了,我想做個小程序,自動檢測iis應用程序池是否被停止,如果停止了就自動啓動它,高手幫忙
用下面代碼可以啓動應用程序池
DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
DirectoryEntry findPool =appPool.Children.Find(AppPoolName,"IIsApplicationPool");
findPool.Invoke(method,null);
appPool.CommitChanges();
appPool.Close();
用下面代碼可以檢查一個服務是否被啓動
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController();
sc.ServiceName = AppPoolName;//"MSSQLSERVER";
if( sc.Status != ServiceControllerStatus.Running )
sc.Start();
問題是怎麼用這個檢測iis應用程序池是否被停止了,高手幫忙,謝謝拉
在你上面的代碼中不是可以取得“IIS://localhost/W3SVC”這個對象麼?
那麼應該可以得到“IIS://localhost/W3SVC/IIsWebServer”這個對象,你可以檢查這個對象的“ServerState”屬性。
ServerState Result:
1: Starting
2: Started
3: Stopping
4: Stopped
5: Pausing
6: Paused
7: Continuing