| Author |
Message |
goh6613 Junior Member
Joined: 18 May 2006 Posts: 3
|
Posted: 05-18-2006 02:08 AM Post subject: programmatically add new host in DNS using vb.net |
|
|
hi all,
i face a problem now ......i would like to programmatically add new host to DNS using vb.net ....
does anyone have an idea to solve this problem, if possible try to paste the sample code here.
thanks |
|
| Back to top |
|
 |
goh6613 Junior Member
Joined: 18 May 2006 Posts: 3
|
Posted: 05-18-2006 07:07 PM Post subject: programmatically add new host in DNS using vb.net |
|
|
hi .....i am using the code below to add new host in DNS....but it return me an error 'Generic Failure'
may i know what is the problem of this code.........
Dim DnsServer As String = "10.0.1.3"
Dim conOptions As ConnectionOptions = New ConnectionOptions
conOptions.Authentication = AuthenticationLevel.Packet
conOptions.Impersonation = ImpersonationLevel.Impersonate
Dim sServerPath As String = "\\" & DnsServer & "\root\microsoftdns"
Dim oScope As ManagementScope = New ManagementScope(sServerPath, conOptions)
oScope.Connect()
Dim oQuery As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM MicrosoftDNS_AType")
oQuery.Scope = oScope
Dim oClass As ManagementClass = New ManagementClass(oScope, New ManagementPath("MicrosoftDNS_AType"), Nothing)
Dim oInParams As ManagementBaseObject = oClass.GetMethodParameters("CreateInstanceFromPropertyData")
oInParams("DnsServerName") = DnsServer
oInParams("ContainerName") = "Mycomcity"
oInParams("OwnerName") = "Mycomcity.dev.ss.lan"
oInParams("IPAddress") = "10.0.1.3"
Dim oOutParams As ManagementBaseObject = oClass.InvokeMethod("CreateInstanceFromPropertyData", oInParams, Nothing)
and is this code is correct to create new host in DNS...
thanks |
|
| Back to top |
|
 |
goh6613 Junior Member
Joined: 18 May 2006 Posts: 3
|
Posted: 05-21-2006 11:29 PM Post subject: |
|
|
hi,
if anyone got sample code which use WMI to solve this problem .........pls let me know.......cos i might want to try to solve it by using WMI also....
thanks |
|
| Back to top |
|
 |
lasso Junior Member
Joined: 20 Nov 2006 Posts: 1
|
Posted: 11-20-2006 06:33 AM Post subject: |
|
|
Hi!
I've got sample code in C#:
[code:1]
public void CreateHostSameAsParent()
{
try
{
ManagementScope scope = new ManagementScope( "\\\\.\\root\\MicrosoftDNS" );
ManagementClass classInstance = new ManagementClass( scope, new ManagementPath( "MicrosoftDNS_AType" ), null );
ManagementBaseObject inParams = classInstance.GetMethodParameters( "CreateInstanceFromPropertyData" );
inParams["ContainerName"] = "xxxx.com";
inParams["DnsServerName"] = "myserver";
inParams["IPAddress"] = "0.0.0.0";
inParams["OwnerName"] = "xxxx.com";
inParams["RecordClass"] = 1;
ManagementBaseObject outParams = classInstance.InvokeMethod( "CreateInstanceFromPropertyData", inParams, null );
}
catch ( ManagementException err )
{
MessageBox.Show( "An error occurred while trying to execute the WMI method: " + err.Message );
}
}
[/code:1]
Bye,
Lasso
www.webdot.hu
webdesign, developing, web hosting automation |
|
| Back to top |
|
 |
|