Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GPO WINS Script not Working

Posted on 2011-03-04
6
Medium Priority
?
758 Views
Last Modified: 2012-06-21
I have a simple script here that seems to execute but, doesn't change the DNS or WINS on the computer it runs on.  I have tried running it manually and from GPO.  Can I get a second set of eyes on this?

Please note that this is the third itteration of the script that I have found on the net.  None of them work!

I am trying to run these on my local computer as well to see if anything changes.  I am the domain admin and am logged in as such so, there shouldn't be any permission issues here.

I have even debugged the script to make sure the values are correct and that the .SetWINSServer  function is available and the right adapter is being worked on (I only have 1 adapter on this machine).

I am running Windows XP with all updates and service packs and my AD server is Windows 2003 Enterprise R2.


On Error Resume Next

Const STR_NEWDNS1 = "10.0.1.35" 
Const STR_NEWDNS2 = "0.0.0.0"
Const STR_NEWWINS1= "10.0.1.35" 
Const STR_NEWWINS2= "0.0.0.0"

SetDnsWins		

Sub SetDnsWins
	strWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//."
	Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration" )

	For Each objNIC In objNICs
		If objNIC.IPEnabled Then
			objNIC.SetWINSServer STR_NEWWINS1,STR_NEWWINS2
			objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1,STR_NEWDNS2)
		End If
	Next

End Sub

Open in new window

0
Comment
Question by:cefranklin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
xchange earned 2000 total points
ID: 35043972
Hi there!,

 For start, I found that it doesn't like the "0.0.0.0" address that you supplied for WINS2.
Change it to WINS1's address and all should be fine.

Check it and let me know how it goes.

Theo
0
 
LVL 2

Expert Comment

by:xchange
ID: 35043989
...or change:
Const STR_NEWWINS2= "0.0.0.0"
to:
Const STR_NEWWINS2= ""
0
 
LVL 2

Expert Comment

by:xchange
ID: 35044140
I tested successfully with WINS, you may have to change:
Const STR_NEWDNS2 = "0.0.0.0"
to:
Const STR_NEWDNS2 = ""

See how it goes and let me know, OK?
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 15

Expert Comment

by:markdmac
ID: 35046587
Give this a shot.

Change the IPs as needed.  

To run in a GPO change the line:
              strComputer = InputBox("Enter Computer Name","Enter Target")
To be:
              strComputer = "."


Also if you only have one WINS and DNS server let me know, there are additional tweaks to make and I will be happy to make them for you.
'==========================================================================
'
' NAME: Set_DNS_WINS_Remotely.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL   : http://www.thespidersparlor.com    
' COPYRIGHT (C) 2009 All rights reserved
' DATE  : 4/24/2009
'
' COMMENT: 
'
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'==========================================================================
On Error Resume Next
strComputer = InputBox("Enter Computer Name","Enter Target")  

strWins1 = "192.168.20.150"
strWins2 = "192.168.20.41"
strDNS1 = "192.168.20.150"
strDNS2 = "192.168.20.41"
 
Set objWMIService = GetObject("winmgmts:" _  
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  
  
Set colNetCards = objWMIService.ExecQuery _  
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled =  True")  
  
For Each objNetCard in colNetCards  
  arrDNSServers = Array(strDNS1, strDNS2)  
  objNetCard.SetDNSServerSearchOrder(arrDNSServers)  
  intSetWINS = objNetCard.SetWINSServer(strWINS1, strWINS2)
  If intSetWINSServer = 0 Then
    WScript.Echo "Success! WINS & DNS servers configured."
  ElseIf intSetWINSServer = 1 Then
    WScript.Echo "WINS  & DNS servers configured, please reboot."
  Else
    WScript.Echo "Error!! Unable to configure WINS & DNS servers."
  End If
Next

Open in new window

0
 
LVL 2

Author Comment

by:cefranklin
ID: 35053299
Will test Monday thanks for the replies.
0
 
LVL 2

Author Closing Comment

by:cefranklin
ID: 35057132
Alright, I thought I tried that but, since it works now, I guess I will chalk it up to me being an idiot :P
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question