2012-02-17 69 views
0

我有一个脚本收集IIS中的所有站点,并通过电子邮件发送一些审计细节。我想对其进行调整,以便仅通过电子邮件发送正在运行的网站。我不需要知道停止的网站。我已经参考了IIS中的所有DirectoryEntry,但我没有看到任何可以指示它是否正在运行的属性。以编程方式确定IIS站点是否正在运行

这是如何完成的?理想情况下,这应该在IIS6和IIS7上运行。

+5

拉梅方式:使用'WebClient'请求主页,看看你得到任何形式的回应。 :/ – 2012-02-17 18:25:55

+1

DL:我根本不认为这是跛脚。 – JohnC 2012-02-17 18:28:02

回答

3

DirectoryEntry.Properties集合,包含一个ServerState属性。它没有很好的记录,但我发现this blogger创建了自己的枚举,看起来是正确的。枚举是

public enum ServerState 
{ 
    Unknown = 0, 
    Starting = 1, 
    Started = 2, 
    Stopping = 3, 
    Stopped = 4, 
    Pausing = 5, 
    Paused = 6, 
    Continuing = 7 
} 

利用这一点,逻辑来检查DirectoryEntry运行,你可以使用:

DirectoryEntry entry; 
ServerState state = (ServerState)Enum.Parse(typeof(ServerState), entry.Properties["ServerState"].Value.ToString()) 
if (state == ServerState.Stopped || state == ServerState.Paused) 
{ 
    //site is stopped 
} 
         { 
相关问题