[英]Check the status of an application pool (IIS 6) with C#
How can I check the status of an IIS6 application pool with C# ? 如何使用C#检查IIS6应用程序池的状态? For example, I want to know if it is running or not ! 例如,我想知道它是否正在运行! Thank's in advance for your help ! 在此先感谢您的帮助 !
http://msdn.microsoft.com/en-us/library/ms524962.aspx http://msdn.microsoft.com/en-us/library/ms524962.aspx
You can do this checking the AppPoolState Property: 您可以检查AppPoolState属性:
protected void status()
{
string appPoolName = "dev.somesite.com";
string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
int intStatus = 0;
try
{
DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
intStatus = (int)w3svc.InvokeGet("AppPoolState");
switch (intStatus)
{
case 2:
lblStatus.Text = "Running";
break;
case 4:
lblStatus.Text = "Stopped";
break;
default:
lblStatus.Text = "Unknown";
break;
}
}
I think you need the services of WMI ( Windows Management Instrumentation) 我认为你需要WMI服务(Windows Management Instrumentation)
There are several articles around on how to manage IIS using WMI via vbscript, eg 关于如何使用WMI通过vbscript管理IIS有几篇文章,例如
http://learn.iis.net/page.aspx/163/managing-applications-and-application-pools-on-iis-70-with-wmi/ http://learn.iis.net/page.aspx/163/managing-applications-and-application-pools-on-iis-70-with-wmi/
If you take one of those articles you should be able to adapt it to C# easily enough. 如果您选择其中一篇文章,您应该能够轻松地将其适应C#。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.