Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HOWTO: create a DNS record using WMI and .NET

12 views
Skip to first unread message

Steen Tøttrup

unread,
Apr 25, 2003, 3:24:09 PM4/25/03
to
I'm really stuck here, and hope somebody can help me!!
I've figured out how to change and delete existing records, but can't get
the last bit right.
This is how I expected it to work, but I get "Invalid operation" when
calling Put on the MangementObject.

What am I missing ??

best regards,
Steen Tųttrup

----------------------

ManagementPath Path = new ManagementPath();
Path.ClassName = "MicrosoftDNS_ResourceRecord";
Path.NamespacePath = "\\\\server\\root\\microsoftdns";

ManagementClass Class = new ManagementClass(Path);
ManagementObject oManObject = Class.CreateInstance();

string sLocalPrimary = sPrimaryName;
if (!sLocalPrimary.EndsWith(".")) {
sLocalPrimary += ".";
}

oManObject["ContainerName"] = "test.dk.";
oManObject["DnsServerName"] = "server.test.dk";
oManObject["DomainName"] = "test.dk";
oManObject["OwnerName"] = "www.test.dk";
oManObject["RecordData"] = "test.dk.";
oManObject["TextRepresentation"] = "www.test.dk IN CNAME test.dk.";
oManObject["TTL"] = 3600;
oManObject.Put();


Andy Cheung [MSFT]

unread,
Apr 27, 2003, 1:47:57 PM4/27/03
to
The error means the provider doesn't support such syntax to create an object of MicrosoftDNS_ResourceRecord. Have you tried to use MicrosoftDNS_ResourceRecord.CreateInstanceFromTextRepresentation WMI method?

--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
 
"Steen Tøttrup" <som...@somewhere.co> wrote in message news:#fub0B2C...@TK2MSFTNGP12.phx.gbl...
I'm really stuck here, and hope somebody can help me!!
I've figured out how to change and delete existing records, but can't get
the last bit right.
This is how I expected it to work, but I get "Invalid operation" when
calling Put on the MangementObject.

What am I missing ??

best regards,
Steen Tøttrup

Steen Tøttrup

unread,
Apr 29, 2003, 12:27:53 PM4/29/03
to

Do you mean something like this ??

string sPath =
"\\\\server\\root\\microsoftdns:MicrosoftDNS_ResourceRecord.DnsServerName=\"
" + sServer + "\"";

ManagementObject oManObject = new ManagementObject(sPath);

InvokeMethodOptions Options = new InvokeMethodOptions();
Options.Context.Add("DnsServerName", sServer);
Options.Context.Add("ContainerName", sDomainName);
Options.Context.Add("TextRepresentation", sTextRepresentation);
ManagementBaseObject oOutput =
oManObject.InvokeMethod("CreateInstanceFromTextRepresentation", oManObject,
Options);


Yes, I had a try with this, but it leaves me with an "Invalid object path"
error in the InvokeMethod call.
If I leave the "DnsServerName=" out of the path, I get an error in the new
ManagementObject line..

Any ideas as to what I'm doing wrong ??

best regards,
Steen

Andy Cheung [MSFT]

unread,
Apr 29, 2003, 2:33:22 PM4/29/03
to
InvokeMethodOptions object is not designed to pass input parameters to a WMI method. Instead, you would either use an object array or a ManagementBaseObject object. e.g.
 
Assuming the WMI method to be invoked is a static method, you would invoke it like below:

ManagementClass dnsRRClass = new ManagementClass(
 @"\\ServerNameHere\root\MicrosoftDNS", 
  "MicrosoftDNS_ResourceRecord",
  null);
ManagementBaseObject inParams = dnsRRClass.GetMethodParameters("CreateInstanceFromTextRepresentation");
inParams["DnsServerName"] = sServer;
inParams["ContainerName"] = sDomainName;
inParams["TextRepresentation"] = sTextRepresentation;
ManagementBaseObject outParams = dnsRRClass.InvokeMethod("CreateInstanceFromTextRepresentation", inParams, null);
Console.WriteLine("Executing the method returns {0}", outParams["ReturnValue"]);

Reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconexecutingmethodsonmanagementobjects.asp
--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
 
"Steen Tøttrup" <som...@somewhere.co> wrote in message news:uJw0KymD...@TK2MSFTNGP10.phx.gbl...

Steen Tųttrup

unread,
Apr 30, 2003, 4:45:42 AM4/30/03
to
Thank you very much...!! Just what I needed..!!

best regards,
Steen Tųttrup


"Andy Cheung [MSFT]" <ha...@online.microsoft.com> wrote in message
news:OyfPR3nD...@TK2MSFTNGP12.phx.gbl...


"Steen Tųttrup" <som...@somewhere.co> wrote in message

Thomas Lee

unread,
Apr 30, 2003, 4:47:58 AM4/30/03
to
In message <uklLkUO...@TK2MSFTNGP12.phx.gbl>, "Andy Cheung [MSFT]"
<ha...@online.microsoft.com> writes

>The error means the provider doesn't support such syntax to create an
>object of MicrosoftDNS_ResourceRecord. Have you tried to use
>MicrosoftDNS_ResourceRecord.CreateInstanceFromTextRepresentation WMI
>method?

Can this be done using WMIC???


Thomas
--
Thomas Lee
(t...@psp.co.uk)

Andy Cheung [MSFT]

unread,
Apr 30, 2003, 11:26:06 PM4/30/03
to
Yes. e.g.
 
C:\>wmic
wmic:root\cli>/namespace:\\root\MicrosoftDNS
wmic:root\cli>path MicrosoftDNS_ResourceRecord call CreateInstanceFromTextRepresentation "DnsServerNameHere", "ContainerServerNameHere", "TextRepresentationHere"
 

--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
 
"Thomas Lee" <t...@psp.co.uk> wrote in message news:gCvEJqW+...@qa.com...
0 new messages