以编程方式确定 IIS 站点是否正在运行

发布于 2025-01-06 06:58:05 字数 197 浏览 0 评论 0原文

我有一个脚本,可以收集 IIS 中的所有站点,并通过电子邮件发送一些详细信息以供审核。我想调整它,以便它只向正在运行的网站发送电子邮件。我不需要知道被停止的网站。我已经引用了 IIS 中的所有 DirectoryEntry,但我没有看到任何指示它是否正在运行的属性。

这是怎么做到的?理想情况下,它应该在 IIS6 和 IIS7 上运行。

I have a script that gathers up all sites in IIS and emails a few details for auditing. I want to adjust it so that it only emails sites that are running. I do not need to know about sites that are stopped. I already have a reference to all of the DirectoryEntrys in IIS but I don't see any properties that would indicate if it is running or not.

How is this done? Ideally this should run on both IIS6 and IIS7.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笏见 2025-01-13 06:58:05

DirectoryEntry.Properties 集合包含一个 ServerState 属性。它没有很好地记录,但我发现 这个博主 创建了他自己的枚举,这似乎是正确的。枚举是

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
}
                        {

The DirectoryEntry.Properties collection, contains a ServerState property. It's not documented very well but I found this blogger that created his own enumeration which appears to be correct. The enum is

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

Using this, the logic to check if a DirectoryEntry is running, you would use:

DirectoryEntry entry;
ServerState state = (ServerState)Enum.Parse(typeof(ServerState), entry.Properties["ServerState"].Value.ToString())
if (state == ServerState.Stopped || state == ServerState.Paused)
{
    //site is stopped
}
                        {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文