检测IIS是否已启用

时间:2008-11-20 09:55:28

标签: .net iis installshield

有没有办法检测IIS是否已启用?

我知道如何检查它是否已安装,但我需要知道它是否已安装但未启用。

此外,这可以通过InstallShield本地完成吗?通过.NET检查这一点是可以接受的,因为我们可以编写自定义操作,但如果有IS调用那么这将是理想的。

感谢任何提示/提示,谢谢

2 个答案:

答案 0 :(得分:1)

要检查服务状态,请使用无处不在的WMI(代码为VBScript,只是为了让您了解必要的WMI查询):

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

编辑:我尝试用这个制作一个IS脚本。如果语法错误,请不要打我。

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;

herehere借来的代码,因为我对IS脚本语言一无所知。 ; - )

答案 1 :(得分:1)

除了W3svc服务之外,您还应该检查网站是否已启动

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

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

因此,使用Win32_Service的上述答案将告诉您服务是否已启动,除了告诉您服务是否正在运行外,还会告诉您网站是否正在运行。