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

Answers


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  
1      Starting    MD_SERVER_STATE_STARTING
2      Started     MD_SERVER_STATE_STARTED  <-- What you want
3      Stopping    MD_SERVER_STATE_STOPPING
4      Stopped     MD_SERVER_STATE_STOPPED
5      Pausing     MD_SERVER_STATE_PAUSING
6      Paused      MD_SERVER_STATE_PAUSED
7      Continuing  MD_SERVER_STATE_CONTINUING

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")
Next

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;
NUMBER i;
BOOL IISrunning;
begin

  IISrunning = false;
  try
    set wmi = CoGetObject( "winmgmts://.", "" );
    if ( !IsObject(wmi) ) then 
      MessageBox("Failed to connect to WMI.", WARNING);
      return false;
    endif;
    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;
    endif;
    for i = 0 to slist.Count-1
      set obj = slist.Item(i);
      IISrunning = (obj.state = "Running");
    endfor;
  catch
    MessageBox(Err.Description, WARNING);
    return false;
  endcatch;

  return IISrunning;
end;

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


Need Your Help

Program that gets input and reverse the string

loops reverse charat

My code is suppose to use loops only, I am suppose to make a string reverse and return that reverse value. I have a problem return the reverse value and I have no clue how to do it.`

Java Web application Displaying data from SQL join

java database jsp web-applications

I have two db tables. One table contains Forecast data. The second table contains Actual data. I have two javabeans that represent each of these tables.

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.