Detect if IIS is enabled

Is there a way to determine if IIS is enabled or not?

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

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

Any hints / advice is appreciated, thanks

+1


source to share


2 answers


You should also check if the website is running, 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 running or not, it will tell you if the website is running in addition to telling you if the service is running.

+1


source


To check the status of a service, use the ubiquitous WMI (VBScript code to give you an idea of ​​the WMI request):

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 am trying to 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 .; -)

+1


source







All Articles