How can I check the 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 !
Asked
Active
Viewed 1.1k times
3
-
You can find this on link https://stackoverflow.com/questions/18349532/an-application-which-fetches-iis-and-app-pool-details-of-website-hosted-in-remot/48164885#48164885 – ಅನಿಲ್ Jan 09 '18 at 09:29
2 Answers
11
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;
}
}

James Campbell
- 5,057
- 2
- 35
- 54
-
Above code is running, but this need more information as its giving an error of "Access Denied". Can you make some light on it. – Kartik Goyal Dec 15 '14 at 19:15
-
@KartikGoyal: Disable firewall from AdministrativeTools-->Windows Firewall and Advanced Setting works for me. – Rahul Hendawe Jun 07 '16 at 07:26
-
Above Code helped me to find the details. I have updated the above method in below link. https://stackoverflow.com/questions/18349532/an-application-which-fetches-iis-and-app-pool-details-of-website-hosted-in-remot/48164885#48164885 – ಅನಿಲ್ Jan 09 '18 at 09:30
0
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.

Justin
- 84,773
- 49
- 224
- 367