Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8679451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:58:33+00:00 2026-06-12T20:58:33+00:00

I am currently able to detect whether a IIS Website is started/paused/stopped using the

  • 0

I am currently able to detect whether a IIS Website is started/paused/stopped using the following code:

public int GetWebsiteStatus(string machineName, int websiteId)
{
    DirectoryEntry root = new DirectoryEntry(
        String.Format("IIS://{0}/W3SVC/{1}", machineName, websiteId));
    PropertyValueCollection pvc = root.Properties["ServerState"];
    return pvc.Value
    // - 2: Website Started
    // - 4: Website Stopped
    // - 6: Website Paused
}

I also want to detect if a Website is suspended or not. If the Website is suspended the method above still returns 2 (which is correct) but not enough for me.

I cannot find any code which do the job for IIS6 and higher.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:58:35+00:00Added an answer on June 12, 2026 at 8:58 pm

    Ah, do you mean the App Pool as stopped because of the timeout configuration? This is a different state to the web site remember? Well, certainly, you could change the settings so it doesn’t recycle, but you could also try using code like this;

    First, add a reference to \Windows\System32\inetsrv\Microsoft.Web.Administration.dll, then;

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Web.Administration;
    namespace MSWebAdmin_Application
    {
        class Program
        {
            static void Main(string[] args)
            {
                ServerManager serverManager = new ServerManager();
                Site site = serverManager.Sites["Default Web Site"];
    
                // get the app for this site
                var appName = site.Applications[0].ApplicationPoolName;
                ApplicationPool appPool = serverManager.ApplicationPools[appName];
    
                Console.WriteLine("Site state is : {0}", site.State);
                Console.WriteLine("App '{0}' state is : {1}", appName, appPool.State);
    
                if (appPool.State == ObjectState.Stopped)
                {
                    // do something because the web site is "suspended"
                }
            }
        }
    }
    

    That code will independantly check the state of your appPool as opposed to your web site. It’s possible for the web site to return “started” and the appPool to return “stopped”.

    See if it works in your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to detect whether the current language my user is
Currently I am able to retrieve data from a MySQL db by using HTTP
I am currently working on an application that should be able to detect wifi
I need to be able to detect whether the current language my user is
I am using javax.script in Java, and I'd like to be able to detect
I'm developing a wordpress plugin that needs to be able to detect whether the
I am currently able to export my MySQL query to a tab delimited text
Currently, I'm finding a lib able to stream video from multiple sources through one
I am currently developing an application and I need to be able when pressing
I am currently writing a Employee store and I need to be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.