Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB script to change Primary and Secondary DNS

Status
Not open for further replies.

deliyurek007

Vendor
May 7, 2009
8
0
0
NL
Hi Guys,

I have a script that change your network interface card withe the DNS entry what do you want.
But the problemm is If i have 2 a 4 network card on my server it will be changed like the first or second card but not all the cards are configurered with the Primary and Secondery DNS interface sometimes the first and second card has been used like extrenal adress not internal. Is it possible to put entry's on the script like If you find or defined or configurered like 192.168.1.2 / 192.168.1.3 change to that adress what has been definied on the script.
It is more check before it changed.

See the script what i have.:

************************
' create objects
Set objWshShell = WScript.CreateObject("Wscript.Shell")

' Network Info
arrDNSServers = Array ("192.168.0.3","192.168.0.4")

strComputer = "."
'For more than one computer open up file
'and loop
'read computer name
Change_DNS_Address strComputer, arrDNSServers
'end loop

'--------------------------------------------
Sub Change_DNS_Address (strComputer, arrDNSServers)

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

'Get Network Cards from WMI
Set colNicConfigs = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

' Sets DNS #s for each NIC
For Each objNicConfig In colNicConfigs
intStaticReturn = objNicConfig.EnableStatic(arrIPAddresses, arrSubnetMasks)
Set objNicChanged = objWMIService.Get("Win32_NetworkAdapterConfiguration.Index=" & objNicConfig.Index)
intDNSServers = objNicChanged.SetDNSServerSearchOrder(arrDNSServers)
Next
--*******************

Maybe some body nows how can i put the rule to look at it and chaged it. Does have anybody a solution for that.
 
I have no idea what a "VB script" might be. If you mean VBScript you might ask in that forum though: forum329
 
As dilettante said, it appears you are using VBScript, not Visual Basic 5/6. Repost this question in the VBScript forum that dilettante pointed you to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top