V
vbnetdev
hi all,
This code works to add a nameserver to a container in DNS using vb.net and
WMI. Howeer the code below that to add host records such as WWW and to add
an MX record does not. It ojects with "invalid path" complaints. Any ideas
what I am doing wrong? This is vb.net 2005 and the platform is Windows
Server 2003 SP1.
'code works
Dim classInstance3 As New ManagementObject( _
"root\MicrosoftDNS", _
"MicrosoftDNS_NSType.ContainerName='" &
queryObj("ContainerName") & "',DnsServerName='" & queryObj("DnsServerName")
& "',DomainName='" & queryObj("DomainName") & "',OwnerName='" &
queryObj("OwnerName") & "',RecordClass='" & queryObj("RecordClass") &
"',RecordData='" & queryObj("DnsServerName") & ".'", _
Nothing)
Dim inParamsNS2 As ManagementBaseObject = _
classInstance3.GetMethodParameters("CreateInstanceFromPropertyData")
' Add the input parameters.
inParamsNS2("ContainerName") = queryObj("ContainerName")
inParamsNS2("DnsServerName") = queryObj("DnsServerName")
inParamsNS2("NSHost") = NameserverHost2
inParamsNS2("OwnerName") = queryObj("ContainerName")
inParamsNS2("RecordClass") = queryObj("RecordClass")
inParamsNS2("TTL") = TTL
Dim outParamsNS2 As ManagementBaseObject = _
classInstance3.InvokeMethod("CreateInstanceFromPropertyData",
inParamsNS2, Nothing)
'does not work to add host record - invalid path or method not found. This
is the first host record being added. The owner name field troubles me. It
seems to refer to a presently existing host record though none exists yet. I
tried (OwnerName=" & Nothing & ", etc). I reverted to hard coding for
demonstrating here. thank you for any help.
Dim classInstance As New ManagementObject( _
"root\MicrosoftDNS", _
"MicrosoftDNS_AType.ContainerName='zz.com',DnsServerName='w2k3.JJK.ds.',DomainName='zz.com',OwnerName='zz.com',RecordClass='1',RecordData='155.155.1.143'",
_
Nothing)
' Obtain [in] parameters for the method
Dim inParams As ManagementBaseObject = _
classInstance.GetMethodParameters("CreateInstanceFromPropertyData")
' Add the input parameters.
inParams("ContainerName") = "zz.com"
inParams("DnsServerName") = "myserver.DOMAINNAME.ds."
inParams("IPAddress") = "10.10.10.10"
inParams("OwnerName") = "ftp"
inParams("RecordClass") = 1
inParams("TTL") = 3600
Dim outParams As ManagementBaseObject = _
classInstance.InvokeMethod("CreateInstanceFromPropertyData",
inParams, Nothing)
' List outParams
Console.WriteLine("Out parameters:")
Console.WriteLine("RR: {0}", outParams("RR"))
Catch err As ManagementException
MessageBox.Show("An error occurred while trying to execute
the WMI method: " & err.Message)
End Try
This code works to add a nameserver to a container in DNS using vb.net and
WMI. Howeer the code below that to add host records such as WWW and to add
an MX record does not. It ojects with "invalid path" complaints. Any ideas
what I am doing wrong? This is vb.net 2005 and the platform is Windows
Server 2003 SP1.
'code works
Dim classInstance3 As New ManagementObject( _
"root\MicrosoftDNS", _
"MicrosoftDNS_NSType.ContainerName='" &
queryObj("ContainerName") & "',DnsServerName='" & queryObj("DnsServerName")
& "',DomainName='" & queryObj("DomainName") & "',OwnerName='" &
queryObj("OwnerName") & "',RecordClass='" & queryObj("RecordClass") &
"',RecordData='" & queryObj("DnsServerName") & ".'", _
Nothing)
Dim inParamsNS2 As ManagementBaseObject = _
classInstance3.GetMethodParameters("CreateInstanceFromPropertyData")
' Add the input parameters.
inParamsNS2("ContainerName") = queryObj("ContainerName")
inParamsNS2("DnsServerName") = queryObj("DnsServerName")
inParamsNS2("NSHost") = NameserverHost2
inParamsNS2("OwnerName") = queryObj("ContainerName")
inParamsNS2("RecordClass") = queryObj("RecordClass")
inParamsNS2("TTL") = TTL
Dim outParamsNS2 As ManagementBaseObject = _
classInstance3.InvokeMethod("CreateInstanceFromPropertyData",
inParamsNS2, Nothing)
'does not work to add host record - invalid path or method not found. This
is the first host record being added. The owner name field troubles me. It
seems to refer to a presently existing host record though none exists yet. I
tried (OwnerName=" & Nothing & ", etc). I reverted to hard coding for
demonstrating here. thank you for any help.
Dim classInstance As New ManagementObject( _
"root\MicrosoftDNS", _
"MicrosoftDNS_AType.ContainerName='zz.com',DnsServerName='w2k3.JJK.ds.',DomainName='zz.com',OwnerName='zz.com',RecordClass='1',RecordData='155.155.1.143'",
_
Nothing)
' Obtain [in] parameters for the method
Dim inParams As ManagementBaseObject = _
classInstance.GetMethodParameters("CreateInstanceFromPropertyData")
' Add the input parameters.
inParams("ContainerName") = "zz.com"
inParams("DnsServerName") = "myserver.DOMAINNAME.ds."
inParams("IPAddress") = "10.10.10.10"
inParams("OwnerName") = "ftp"
inParams("RecordClass") = 1
inParams("TTL") = 3600
Dim outParams As ManagementBaseObject = _
classInstance.InvokeMethod("CreateInstanceFromPropertyData",
inParams, Nothing)
' List outParams
Console.WriteLine("Out parameters:")
Console.WriteLine("RR: {0}", outParams("RR"))
Catch err As ManagementException
MessageBox.Show("An error occurred while trying to execute
the WMI method: " & err.Message)
End Try