ChangeIP.com Forum Index ChangeIP.com
Dynamic DNS Forums
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

programmatically add new host in DNS using vb.net

 
Post new topic   Reply to topic    ChangeIP.com Forum Index -> How Do I?
Author Message
goh6613
Junior Member


Joined: 18 May 2006
Posts: 3

PostPosted: 05-18-2006 02:08 AM    Post subject: programmatically add new host in DNS using vb.net Reply with quote

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

PostPosted: 05-18-2006 07:07 PM    Post subject: programmatically add new host in DNS using vb.net Reply with quote

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

PostPosted: 05-21-2006 11:29 PM    Post subject: Reply with quote

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

PostPosted: 11-20-2006 06:33 AM    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    ChangeIP.com Forum Index -> How Do I? All times are GMT - 8 Hours
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group