Solved

GPO WINS Script Not Working #2

Posted on 2011-03-09
12
687 Views
Last Modified: 2013-11-25
Alright, this is a continuation of my original question, here http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26865173.html

Now, the script will set the WINS and the DNS.  I want the script to see if the values are set first.  If they are, leave it alone.  Since this script will be run every time the computer starts, I don't want to make any undue changes.

So, I've added some if statements.  The first If statement for the WINS works fine but, the second for the DNS is failing.

I have included a screenshot.  What is happening in debug, as you can see is, the DNSSearchServerOrder is null but, the if statement is not returning true.

Second, when it gets to the second if statement, the script abruptly stops. This is most likly becuase it is out of bounds as the array is null.  I have also tried with Len() and that fails as well.

Notice the debug window at the bottom.  Property 17 is for the objNIC.  It is an array and the value is null.  Why would the script say that it is not null?

Am I missing something like initializing my own array and setting it with the one off the nic to perform operations against?

Totally lost here.

Here is the current script:

On Error Resume Next

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

SetDnsWins "."		

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

	For Each objNIC In objNICs
		If objNIC.IPEnabled Then
			'winsprimary = objNIC.WINSPrimaryServer
			If Not objNIC.WINSPrimaryServer = "10.0.1.35" Then
				objNIC.SetWINSServer STR_NEWWINS1,STR_NEWWINS2
			End If
			If objNIC.DNSServerSearchOrder = null Then
				objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1)
			End If
			If Not objNIC.DNSServerSearchOrder(0) = "10.0.1.35" Then
				objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1)
			End If
		End If
	Next

End Sub

Open in new window


SetWINS.vbs Debug
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
  • 7
  • 5
12 Comments
 
LVL 51

Expert Comment

by:Netman66
ID: 35093897
In line 20 try changing the value "null" to "Null".

VB is weird sometimes with case.

0
 
LVL 2

Author Comment

by:cefranklin
ID: 35095111
Did that no go
0
 
LVL 51

Expert Comment

by:Netman66
ID: 35095151
If you replace Null with " ", does it change anything?

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:cefranklin
ID: 35095958
That doesn't work either.  The script ends abruptly like the second part when I try to access an array that is null.
0
 
LVL 2

Author Comment

by:cefranklin
ID: 35095978
I am just doing at the command prompt cscript /X SetWINS.vbs then selecting a debugger and running through it.  Will try taking off the On Error Resume Next and see what happens.
0
 
LVL 2

Author Comment

by:cefranklin
ID: 35096004
Microsoft VBScript runtime error: Type mismatch when using the " " to compare...
and same thing when comparing to Null
0
 
LVL 51

Expert Comment

by:Netman66
ID: 35096035
RobSampson is the defacto man here.  I'm hoping he steps in.

Since the whole script isn't there, I can't run it up here.

0
 
LVL 51

Expert Comment

by:Netman66
ID: 35096044
What about removing the space - ""?

As I don't have time to build up the missing section above your snippet, I can't test it here to see what gives.

0
 
LVL 2

Author Comment

by:cefranklin
ID: 35096071
There is no missing section, that is the whole script heh.  Maybe I am approaching this wrong.  Instead of comparing to null and it says it is not, I am thinking if I say Not null and see what happens.
0
 
LVL 2

Author Comment

by:cefranklin
ID: 35096570
Tried removing the space in " " and that is a type mismatch as well.
0
 
LVL 51

Accepted Solution

by:
Netman66 earned 500 total points
ID: 35097594
Ok, I think I've got it.

Change line 20 to this:

If IsNull(objNIC.DNSServerSearchOrder) Then


Let me know
0
 
LVL 2

Author Closing Comment

by:cefranklin
ID: 35098349
That worked, thanks so much!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

740 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