开发者

Check the status of an application pool (IIS 6) with C#

开发者 https://www.devze.com 2022-12-24 01:10 出处:网络
How can I check t开发者_运维问答he status of an IIS6 application pool with C# ? For example, I want to know if it is running or not !

How can I check t开发者_运维问答he status of an IIS6 application pool with C# ? 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

You can do this checking the AppPoolState Property:

 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)

There are several articles around on how to manage IIS using WMI via vbscript, e.g.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号