用c#怎么检测iis应用程序池是否被停止了,即它的状态

我的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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章