Detect whether IIS is Enabled

Is there a way to detect whether IIS is enabled or not?

I know how to check if it is INSTALLED, but I need to know if it's installed but not enabled.

Also, can this be done natively via InstallShield? Checking this via .NET would be acceptable as we can write custom actions, but if there is an IS call then that would be ideal.

Any hints/tips are appreciated, thanks


You should also check to see if the Web Site is started, in addition to the W3svc Service

c:\Inetpub\scripts>adsutil.vbs get W3SVC/1/ServerState
ServerState                     : (INTEGER) 2

Where ServerState =

Value  Meaning  Friendly ID  
2      Started     MD_SERVER_STATE_STARTED  <-- What you want
4      Stopped     MD_SERVER_STATE_STOPPED
5      Pausing     MD_SERVER_STATE_PAUSING
6      Paused      MD_SERVER_STATE_PAUSED

So the above answer using Win32_Service will tell you if the service is started or not, this will tell you if the web site is running in addition to telling you if the service is running.

To check for service status, use the ubiquitous WMI (the code is VBScript, just to give you the idea of the necessary WMI query):

IISrunning = false
wql        = "SELECT state FROM Win32_Service WHERE name = 'W3SVC'"
Set w3svc  = GetObject("winmgmts://.").ExecQuery(wql)

For Each service in w3svc
  IISrunning = (service.State = "Running")

WScript.Echo IISrunning

EDIT: I try and make an IS script out of this. Don't hit me if there is a syntax error.

function BOOL DetectIIS()
OBJECT wmi, slist, obj;
BOOL IISrunning;

  IISrunning = false;
    set wmi = CoGetObject( "winmgmts://.", "" );
    if ( !IsObject(wmi) ) then 
      MessageBox("Failed to connect to WMI.", WARNING);
      return false;
    set slist = wmi.ExecQuery("SELECT state FROM Win32_Service WHERE name = 'W3SVC'");
    if ( !IsObject(slist) ) then
      MessageBox("Failed to get query W3SVC service state.", WARNING);
      return false;
    for i = 0 to slist.Count-1
      set obj = slist.Item(i);
      IISrunning = (obj.state = "Running");
    MessageBox(Err.Description, WARNING);
    return false;

  return IISrunning;

Code borrowed from here and here, because I know zero about the IS scripting language. ;-)

Need Your Help

Android to ASP.NET Upload Savepath

android upload

I am uploading an image from my android device to my ASP.NET MVC server.

Forcing file-creation in public directory?

php security file-io filesystems chmod

Here's an idea. I'm trying to create file from PHP script. File may be created in any public place on server (in public root or in its subdirectories). Bottom of line, I want to write function like...

Polymorphic Associations in .NET

.net sql linq polymorphic-associations entities

How do I effectively/efficiently create polymorphic associations in .NET?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.