如何使用 WMI 删除 DNS 区域

发布于 2024-09-25 08:01:32 字数 424 浏览 0 评论 0原文

我可以创建一个新区域,添加和删除该区域的记录,所有这些都可以使用 WMI 和 System.Management 相对轻松地完成,但我一生都不知道如何删除区域。它似乎不是 WMI 文档中的方法:

http://msdn.microsoft.com/en-us/library/ms682123(VS.85).aspx

关于如何执行此操作有什么想法吗?当我们删除旧网站客户时,试图保持 DNS 服务器干净,但我只能删除一个区域中的所有记录。

编辑:这是在 Windows Server 2008 R2 机器上。如果有一个可以从远程计算机执行的替代解决方案和 C# 代码,我可以接受“不使用 WMI”的答案

I can create a new zone, add and delete records for that zone, all relatively easily using WMI and System.Management, but for the life of me can't figure out how to delete a zone. It doesn't appear to be a method in the WMI Documentation:

http://msdn.microsoft.com/en-us/library/ms682123(VS.85).aspx

Any thoughts on how to do this? Trying to keep the DNS server clean when we remove old website customers, but I can only get as good as deleting all the records in a zone.

EDIT: This is on a windows server 2008 R2 machine. And I would be ok with an answer of "don't use WMI" if there is an alternate solution I can execute from a remote machine and code in c#

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

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

发布评论

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

评论(1

萝莉病 2024-10-02 08:01:32

您可以按照与删除记录相同的方式删除区域。

internal static bool DeleteZoneFromDns(string ZoneName)
    {
        try
        {
            string Query = "SELECT * FROM MicrosoftDNS_Zone WHERE ContainerName = '" + ZoneName + "'";
            ObjectQuery qry = new ObjectQuery(Query);
            DnsProvider dns = new DnsProvider();
            ManagementObjectSearcher s = new ManagementObjectSearcher(dns.Session, qry);
            ManagementObjectCollection col = s.Get();
            dns.Dispose();

            foreach (ManagementObject obj in col)
            {
                obj.Delete();
            }
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

You can delete zones in the same manner you would a record.

internal static bool DeleteZoneFromDns(string ZoneName)
    {
        try
        {
            string Query = "SELECT * FROM MicrosoftDNS_Zone WHERE ContainerName = '" + ZoneName + "'";
            ObjectQuery qry = new ObjectQuery(Query);
            DnsProvider dns = new DnsProvider();
            ManagementObjectSearcher s = new ManagementObjectSearcher(dns.Session, qry);
            ManagementObjectCollection col = s.Get();
            dns.Dispose();

            foreach (ManagementObject obj in col)
            {
                obj.Delete();
            }
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文