Domanda

Esiste un modo per rilevare se IIS è abilitato o meno?

So come verificare se è INSTALLATO, ma devo sapere se è installato ma non abilitato.

Inoltre, questo può essere fatto in modo nativo tramite InstallShield? Controllare questo tramite .NET sarebbe accettabile in quanto possiamo scrivere azioni personalizzate, ma se c'è una chiamata IS sarebbe l'ideale.

Eventuali suggerimenti / suggerimenti sono apprezzati, grazie

È stato utile?

Soluzione

Dovresti anche verificare se il sito Web è stato avviato, oltre al servizio W3svc

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

Quindi la risposta sopra usando Win32_Service ti dirà se il servizio è avviato o meno, questo ti dirà se il sito web è in esecuzione oltre a dirti se il servizio è in esecuzione.

Altri suggerimenti

Per verificare lo stato del servizio, utilizzare l'onnipresente WMI (il codice è VBScript, solo per darti l'idea della query WMI necessaria):

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: provo a creare uno script IS da questo. Non colpirmi se c'è un errore di sintassi.

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;

Codice preso in prestito da qui e qui , perché non conosco nulla del linguaggio di scripting IS. ; -)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top