Hi,
I am trying to create a CName record on my DNS server. Seems like it
should be easy. I am using WMI. I have created a test asp.net page and put
the code in the code behind. The DNS server is a Windows 2000 box that sits
next to my pc. I have rights on the DNS box and use Remote desktop to admin
it. So here's the problem. When I try to run my code I get a "The RPC
server is unavailable." error.
Here is my code:
using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Manageme nt;
public partial class DNSc : System.Web.UI.P age
{
ManagementScope DNS;
ManagementObjec t DNSSVR;
private string dnsname;
public string sResults = "";
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
new_Zone("myDNS server", "myDomain.com") ;
sResults = "DONE";
}
}
void new_Zone(string dnsserver, string domain)
{
ManagementClass MC;
// connect to WMI *************** *************** connect to WMI
ConnectionOptio ns options = new ConnectionOptio ns();
options.Authent ication =
System.Manageme nt.Authenticati onLevel.PacketP rivacy;
options.Usernam e = "username";
options.Passwor d = "password";
DNS = new ManagementScope ("\\\\" + dnsserver +
"\\root\\micros oftdns",options );
DNSSVR = new ManagementObjec t(DNS, new
ManagementPath( "MicrosoftDNS_S erver.Name=\".\ ""), null);
DNSSVR.Get(); // !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!
dnsname = DNSSVR.Site.Nam e;
// connect to WMI *************** *************** connect to WMI
// create MX-record *************** ************** create MX-record
MC = new ManagementClass (DNS, new
ManagementPath( "MicrosoftDNS_C NAMETYPE"), null);
object[] A2 = { dnsname, domain, domain, 1, 86400, 10, "test." +
domain };
MC.InvokeMethod ("CreateInstanc eFromPropertyDa ta", A2);
// create MX-record *************** ************** create MX-record
}
}
The line where I receive my error is on the "Get()". I put a comment behind
it like this: // !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!
Thank you for any help on this.
Michael.
I am trying to create a CName record on my DNS server. Seems like it
should be easy. I am using WMI. I have created a test asp.net page and put
the code in the code behind. The DNS server is a Windows 2000 box that sits
next to my pc. I have rights on the DNS box and use Remote desktop to admin
it. So here's the problem. When I try to run my code I get a "The RPC
server is unavailable." error.
Here is my code:
using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Manageme nt;
public partial class DNSc : System.Web.UI.P age
{
ManagementScope DNS;
ManagementObjec t DNSSVR;
private string dnsname;
public string sResults = "";
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
new_Zone("myDNS server", "myDomain.com") ;
sResults = "DONE";
}
}
void new_Zone(string dnsserver, string domain)
{
ManagementClass MC;
// connect to WMI *************** *************** connect to WMI
ConnectionOptio ns options = new ConnectionOptio ns();
options.Authent ication =
System.Manageme nt.Authenticati onLevel.PacketP rivacy;
options.Usernam e = "username";
options.Passwor d = "password";
DNS = new ManagementScope ("\\\\" + dnsserver +
"\\root\\micros oftdns",options );
DNSSVR = new ManagementObjec t(DNS, new
ManagementPath( "MicrosoftDNS_S erver.Name=\".\ ""), null);
DNSSVR.Get(); // !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!
dnsname = DNSSVR.Site.Nam e;
// connect to WMI *************** *************** connect to WMI
// create MX-record *************** ************** create MX-record
MC = new ManagementClass (DNS, new
ManagementPath( "MicrosoftDNS_C NAMETYPE"), null);
object[] A2 = { dnsname, domain, domain, 1, 86400, 10, "test." +
domain };
MC.InvokeMethod ("CreateInstanc eFromPropertyDa ta", A2);
// create MX-record *************** ************** create MX-record
}
}
The line where I receive my error is on the "Get()". I put a comment behind
it like this: // !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!
Thank you for any help on this.
Michael.
Comment