Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


help: obtain DNS address automatically

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2690
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> help: obtain DNS address automatically
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 help: obtain DNS address automatically - 4/14/2005 4:04:21 AM   
  stevens

 

Posts: 6
Score: 0
Joined: 4/14/2005
From:
Status: offline
Could somebody give me the piece of wsh code necessary to enable the property "Obtain DNS server address automatically" of a net adapter in Windows XP?
A lot of thanks in advance.
 
 
Post #: 1
 
 Re: help: obtain DNS address automatically - 4/14/2005 5:11:51 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
do you mean dhcp? that is what gets the dns server information automatically.

(in reply to stevens)
 
 
Post #: 2
 
 Re: help: obtain DNS address automatically - 4/14/2005 5:22:12 AM   
  stevens

 

Posts: 6
Score: 0
Joined: 4/14/2005
From:
Status: offline
I've already a wshscript to change from ip static to "obtain an ip address automatically" and it works but... the switch "Obtain DNS address automatically" from my net adapter properties stay unchanged!
Why?How i can change it?
Thanks again.

(in reply to stevens)
 
 
Post #: 3
 
 Re: help: obtain DNS address automatically - 4/14/2005 10:08:00 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Could you post your code.

(in reply to stevens)
 
 
Post #: 4
 
 Re: help: obtain DNS address automatically - 4/14/2005 7:10:47 PM   
  stevens

 

Posts: 6
Score: 0
Joined: 4/14/2005
From:
Status: offline
My wsh code for enable DHCP is

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()

Next

But this code not enable the switch "Obtain DNS server address automatically" in the network adapter properties

(in reply to stevens)
 
 
Post #: 5
 
 Re: help: obtain DNS address automatically - 4/14/2005 7:19:16 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
errEnable = objNetAdapter.EnableDNS

See if that's what you wanted.

Other methods related to DNS include:

EnableDNS
SetDNSDomain
SetDNSServerSearchOrder
SetDNSSuffixSearchOrder
SetDynamicDNSRegistration

Is there any reason you don't want to use GPO for that ?

(in reply to stevens)
 
 
Post #: 6
 
 Re: help: obtain DNS address automatically - 4/15/2005 12:15:54 AM   
  stevens

 

Posts: 6
Score: 0
Joined: 4/14/2005
From:
Status: offline
Firstly, thanks Token for your kindness.
When i try the method

errEnable = objNetAdapter.EnableDNS()

the result is

"Invalid Method
Code: 8004102E
Source: SWbemObjectEx"

Any ideas?

(in reply to stevens)
 
 
Post #: 7
 
 Re: help: obtain DNS address automatically - 4/15/2005 1:40:27 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
are these machines pulling the dns server information from dhcp? if so why worry about it, if not, this might be something you have to set in the registry. id look down that path and see.

(in reply to stevens)
 
 
Post #: 8
 
 Re: help: obtain DNS address automatically - 4/15/2005 9:16:12 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
kirrilian, I think they were all statically configured and he wanted to change this configuration on all machines at once (or something like that).

stevens, what OS do you have ?

(in reply to stevens)
 
 
Post #: 9
 
 Re: help: obtain DNS address automatically - 4/17/2005 10:08:54 PM   
  stevens

 

Posts: 6
Score: 0
Joined: 4/14/2005
From:
Status: offline
State of the art:
Indeed, I have statically assigned the ip addresses of the computers and the ip addresses of the dns servers. With a wsh script i would migrate to a dynamic assignment for the computer ip addresses and for their associated ip dns servers addresses.But when the "DNS server addresses" are statically assigned the wsh script in the Microsoft Script Center Repository only changes the "Obtain an IP Address Automatically" switch but no the "Obtain DNS Server Address Automatically". My S.O. it's Windows XP.
Thank you again for your help.

(in reply to stevens)
 
 
Post #: 10
 
 Re: help: obtain DNS address automatically - 4/18/2005 3:40:11 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
It seems to me that EnableDNS isn't supported when the object collection is returned. However, even it executes without any error this way, it still doesn't seem to change the DNS settings to automatic. I'm not sure what causes it.

Set NetAdapter = objWMIService.Get("Win32_NetworkAdapterConfiguration")
netAdapter.EnableDNS

(in reply to stevens)
 
 
Post #: 11
 
 Re: help: obtain DNS address automatically - 4/18/2005 4:15:40 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
You could possibly also try this.

netAdapter.SetDNSServerSearchOrder

I'm wondering if earsing all DNS server entries will make it revert back to the automatic setting.

Just some thought.

(in reply to stevens)
 
 
Post #: 12
 
 Re: help: obtain DNS address automatically - 4/26/2005 2:24:47 AM   
  warhorse

 

Posts: 7
Score: 0
Joined: 4/24/2005
From:
Status: offline
stevens,

I have been working on a similar problem and fixed the part you are having trouble with.

Change you code from

quote:
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()

Next


to...


      

That should do the trick. Good luck.

(in reply to stevens)
 
 
Post #: 13
 
 Re: help: obtain DNS address automatically - 4/26/2005 3:29:27 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Hi warhorse,

I'm just wondering if "errDNS = objNetAdapter.SetDNSServerSearchOrder" works without the null as the parameter.

Thanks

(in reply to stevens)
 
 
Post #: 14
 
 Re: help: obtain DNS address automatically - 4/27/2005 2:43:55 AM   
  warhorse

 

Posts: 7
Score: 0
Joined: 4/24/2005
From:
Status: offline
quote:
Originally posted by token

Hi warhorse,

I'm just wondering if "errDNS = objNetAdapter.SetDNSServerSearchOrder" works without the null as the parameter.

Thanks





I could only get it to work when the null parameter was there.

(in reply to stevens)
 
 
Post #: 15
 
 Re: help: obtain DNS address automatically - 4/27/2005 4:42:36 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
I see. Thanks for the info ;)

(in reply to stevens)
 
 
Post #: 16
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> help: obtain DNS address automatically Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts