internal static MsDnsCnameRecord Parse(System.Management.ManagementObject record, MsDnsZone zone) { MsDnsCnameRecord dnsRecord = new MsDnsCnameRecord( (string)record.Properties["OwnerName"].Value, (string)record.Properties["RecordData"].Value, zone, (int)(UInt32)record.Properties["TTL"].Value); return(dnsRecord); }
public List <MsDnsCnameRecord> GetCnameRecords(MsDnsZone zone) { ObjectQuery query = new ObjectQuery( "SELECT * FROM MicrosoftDNS_CNAMEType WHERE ContainerName = '" + zone.Name + "'"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(WmiScope, query); ManagementObjectCollection recordCollection = searcher.Get(); List <MsDnsCnameRecord> recordList = new List <MsDnsCnameRecord>(); foreach (ManagementObject record in recordCollection) { recordList.Add(MsDnsCnameRecord.Parse(record, zone)); } return(recordList); }
public void UpdateRecordTtl(MsDnsRecord dnsRecord) { string type = string.Empty; string value = string.Empty; if (dnsRecord is MsDnsARecord) { type = "MicrosoftDNS_AType"; value = dnsRecord.Value; } else if (dnsRecord is MsDnsMxRecord) { MsDnsMxRecord mxRecord = dnsRecord as MsDnsMxRecord; type = "MicrosoftDNS_MXType"; value = mxRecord.Priority + " " + mxRecord.Value; } else if (dnsRecord is MsDnsCnameRecord) { MsDnsCnameRecord cnameRecord = dnsRecord as MsDnsCnameRecord; type = "MicrosoftDNS_CNAMEType"; value = cnameRecord.Value; } else { throw new NotSupportedException( "Derrived DNS record type is not supported."); } ObjectQuery query = new ObjectQuery( "SELECT * FROM " + type + " " + "WHERE OwnerName = '" + dnsRecord.Owner + "' " + "AND RecordData = '" + dnsRecord.Value + "' "); ManagementObjectSearcher searcher = new ManagementObjectSearcher(WmiScope, query); ManagementObjectCollection recordCollection = searcher.Get(); foreach (ManagementObject record in recordCollection) { record.Delete(); } ManagementPath path = new ManagementPath(type); ManagementClass zone = new ManagementClass(WmiScope, path, null); ManagementBaseObject createParams = zone.GetMethodParameters( "CreateInstanceFromPropertyData"); createParams.Properties["DnsServerName"].Value = WmiScope.Path.Server; createParams.Properties["TTL"].Value = dnsRecord.TTL; createParams.Properties["ContainerName"].Value = dnsRecord.Container; createParams.Properties["OwnerName"].Value = dnsRecord.Owner; if (dnsRecord is MsDnsARecord) { createParams.Properties["IPAddress"].Value = dnsRecord.Value; } else if (dnsRecord is MsDnsMxRecord) { MsDnsMxRecord mxRecord = dnsRecord as MsDnsMxRecord; createParams.Properties["Preference"].Value = mxRecord.Priority; createParams.Properties["MailExchange"].Value = dnsRecord.Value; } else if (dnsRecord is MsDnsCnameRecord) { createParams.Properties["PrimaryName"].Value = dnsRecord.Value; } zone.InvokeMethod("CreateInstanceFromPropertyData", createParams, null); }