Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

How to use c# creat dns server zone ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
huang hspeeder - 21 Apr 2005 04:01 GMT
HI
 I try it code only creat DNS ResourceRecord,How to creat dns zone?
 thanks!

this code:

public void CreateRR(string zoneName, string rrTextRep)
        {
            if ( zoneName == null )
                throw new ArgumentNullException("zoneName", "zoneName is null.");
            if ( rrTextRep == null )
                throw new ArgumentNullException("rrTextRep", "rrTextRep is null.");

            InvokeMethodOptions options = new InvokeMethodOptions();
            options.Timeout = new TimeSpan(0,0,0,5);

            ManagementClass rrClass = new
                ManagementClass(@"\\"+ System.Environment.MachineName
                +@"\root\MicrosoftDNS","MicrosoftDNS_ResourceRecord",null);

            //Get an input parameters object for this method
            ManagementBaseObject inParams =
                rrClass.GetMethodParameters("CreateInstanceFromTextRepresentation");

            //Fill in input parameter values
            inParams["DnsServerName"] = null; //Don't need.
            inParams["ContainerName"] = zoneName;
            inParams["TextRepresentation"] = rrTextRep;

            //Execute the method
            try
            {
                ManagementBaseObject outObject = rrClass.InvokeMethod
                    ("CreateInstanceFromTextRepresentation", inParams, null);
                PropertyDataCollection outProperties = outObject.Properties;
                foreach (PropertyData outProperty in outProperties)
                {
                    Console.WriteLine("Property = " + outProperty.Name);
                }
            }
            catch
            {
                throw new ApplicationException
("CreateInstanceFromTextRepresentationmethod failed.");
                                 }
        } // End CreateInstanceFromTextRepresentation Method.
Jamie Nichols - 23 Apr 2005 15:56 GMT
Try this...

//Create Foward Lookup Zone.
string sServerPath = "\\\\localhost\\ROOT\\MicrosoftDNS";
ManagementScope oScope = new ManagementScope(sServerPath);
ManagementPath Path = new ManagementPath("MicrosoftDNS_Zone");
ManagementClass DnsZoneClass = new ManagementClass(oScope, Path, null);
ManagementBaseObject InputParams =
DnsZoneClass.GetMethodParameters("CreateZone");
InputParams["ZoneName"] =  "sample.com";
InputParams["ZoneType"] = Convert.ToInt32(0);
InputParams["DataFileName"] = "sample.com.dns";
ManagementBaseObject OutParams = DnsZoneClass.InvokeMethod("CreateZone",
InputParams, null);

good luck!

Jamie

> HI
>  I try it code only creat DNS ResourceRecord,How to creat dns zone?
[quoted text clipped - 42 lines]
>   }
> } // End CreateInstanceFromTextRepresentation Method.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.