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 ManagementObjec t( _
"root\Microsoft DNS", _
"MicrosoftDNS_N SType.Container Name='" &
queryObj("Conta inerName") & "',DnsServerNam e='" & queryObj("DnsSe rverName")
& "',DomainName=' " & queryObj("Domai nName") & "',OwnerNam e='" &
queryObj("Owner Name") & "',RecordClass= '" & queryObj("Recor dClass") &
"',RecordData=' " & queryObj("DnsSe rverName") & ".'", _
Nothing)
Dim inParamsNS2 As ManagementBaseO bject = _
classInstance3. GetMethodParame ters("CreateIns tanceFromProper tyData")
' Add the input parameters.
inParamsNS2("Co ntainerName") = queryObj("Conta inerName")
inParamsNS2("Dn sServerName") = queryObj("DnsSe rverName")
inParamsNS2("NS Host") = NameserverHost2
inParamsNS2("Ow nerName") = queryObj("Conta inerName")
inParamsNS2("Re cordClass") = queryObj("Recor dClass")
inParamsNS2("TT L") = TTL
Dim outParamsNS2 As ManagementBaseO bject = _
classInstance3. InvokeMethod("C reateInstanceFr omPropertyData" ,
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 ManagementObjec t( _
"root\Microsoft DNS", _
"MicrosoftDNS_A Type.ContainerN ame='zz.com',Dn sServerName='w2 k3.JJK.ds.',Dom ainName='zz.com ',OwnerName='zz .com',RecordCla ss='1',RecordDa ta='155.155.1.1 43'",
_
Nothing)
' Obtain [in] parameters for the method
Dim inParams As ManagementBaseO bject = _
classInstance.G etMethodParamet ers("CreateInst anceFromPropert yData")
' Add the input parameters.
inParams("Conta inerName") = "zz.com"
inParams("DnsSe rverName") = "myserver.DOMAI NNAME.ds."
inParams("IPAdd ress") = "10.10.10.1 0"
inParams("Owner Name") = "ftp"
inParams("Recor dClass") = 1
inParams("TTL") = 3600
Dim outParams As ManagementBaseO bject = _
classInstance.I nvokeMethod("Cr eateInstanceFro mPropertyData",
inParams, Nothing)
' List outParams
Console.WriteLi ne("Out parameters:")
Console.WriteLi ne("RR: {0}", outParams("RR") )
Catch err As ManagementExcep tion
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 ManagementObjec t( _
"root\Microsoft DNS", _
"MicrosoftDNS_N SType.Container Name='" &
queryObj("Conta inerName") & "',DnsServerNam e='" & queryObj("DnsSe rverName")
& "',DomainName=' " & queryObj("Domai nName") & "',OwnerNam e='" &
queryObj("Owner Name") & "',RecordClass= '" & queryObj("Recor dClass") &
"',RecordData=' " & queryObj("DnsSe rverName") & ".'", _
Nothing)
Dim inParamsNS2 As ManagementBaseO bject = _
classInstance3. GetMethodParame ters("CreateIns tanceFromProper tyData")
' Add the input parameters.
inParamsNS2("Co ntainerName") = queryObj("Conta inerName")
inParamsNS2("Dn sServerName") = queryObj("DnsSe rverName")
inParamsNS2("NS Host") = NameserverHost2
inParamsNS2("Ow nerName") = queryObj("Conta inerName")
inParamsNS2("Re cordClass") = queryObj("Recor dClass")
inParamsNS2("TT L") = TTL
Dim outParamsNS2 As ManagementBaseO bject = _
classInstance3. InvokeMethod("C reateInstanceFr omPropertyData" ,
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 ManagementObjec t( _
"root\Microsoft DNS", _
"MicrosoftDNS_A Type.ContainerN ame='zz.com',Dn sServerName='w2 k3.JJK.ds.',Dom ainName='zz.com ',OwnerName='zz .com',RecordCla ss='1',RecordDa ta='155.155.1.1 43'",
_
Nothing)
' Obtain [in] parameters for the method
Dim inParams As ManagementBaseO bject = _
classInstance.G etMethodParamet ers("CreateInst anceFromPropert yData")
' Add the input parameters.
inParams("Conta inerName") = "zz.com"
inParams("DnsSe rverName") = "myserver.DOMAI NNAME.ds."
inParams("IPAdd ress") = "10.10.10.1 0"
inParams("Owner Name") = "ftp"
inParams("Recor dClass") = 1
inParams("TTL") = 3600
Dim outParams As ManagementBaseO bject = _
classInstance.I nvokeMethod("Cr eateInstanceFro mPropertyData",
inParams, Nothing)
' List outParams
Console.WriteLi ne("Out parameters:")
Console.WriteLi ne("RR: {0}", outParams("RR") )
Catch err As ManagementExcep tion
MessageBox.Show ("An error occurred while trying to execute
the WMI method: " & err.Message)
End Try
Comment