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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double Echo's

Status
Not open for further replies.

phildib

IS-IT--Management
Jan 30, 2008
4
US
This is a strange issue I am having with my desktop machines. When I perform a WScript.Echo on Windows 2000 clients it doubles the echo on the screen. This does not happen on any XP clients. Here is a copy of the code I have been testing with, I have narrowed it down to:

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

Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
WScript.Echo "Inside"
Next
End If
Next
WScript.Echo "Outside"

On any Win2000 machine it will Echo IP; "Inside", IP, "Inside", "Outside" In that order. I have tested with a few different scripts and it seems to be doubling the out put anytime an echo is inside the For Each. Thanks for any info.

Phil
 
Replace this:
WScript.Echo IPConfig.IPAddress(i)
with this:
WScript.Echo IPConfig.IPAddress(i) & ", i=" & i

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the quick response. I just updated my script and ran on Win 2000. This is the echo out put:

IP, i=0, inside, IP, i=0, inside, outside
 
what about this ?
...
j = 0
For Each IPConfig in IPConfigSet
j = j + 1
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i) & ", j=" & j
WScript.Echo "Inside"
Next
End If
Next
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The echo reads:

IP, J=1, Inside, IP, J=2, Inside, Outside

Thanks
 
So, now you know why the echo is doubled ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Please excuse me I don't follow. This issue that I am having happens anytime there is a For Each loop in my script not just limited to this example. I am afraid that there may be something not configured right on the client. Sorry
 
What you are seeing is an anomaly of Windows 2000 WMI. What is happening is that you are actually running the Outer For Each...Next loop 2 times, but getting the same results for each one.

Code:
For Each IPConfig in IPConfigSet

	[blue]wscript.echo "Index: " & IPConfig.Index[/blue]

    If Not IsNull(IPConfig.IPAddress) Then
        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
etc...

WMI will report the same NIC in both Index 0 and some other number. (On my test system I got 0 and 8)

Since I don't have a lot of time to research this, I assume the adapter in "Index 0" is the primary NIC of the system on 2000 based on the binding order. XP and 2003 don't do this.

You may need to add some code to detect the OS version. I'll dig through my old scripts and see how I approached this issue...

Good Luck!

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
After taking a look at a couple of XP and 2003 machines, there doesn't appear to be an Index 0 on them. So you could simply simply change your code to skip the NIC marked with Index 0.

I do remember coming up against this issue in the past, but not having to resolve it because all of the clients were XP. So I didn't have to find a solution for 2000.

Good Luck!

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
I don't understand what is it all about: "double", "anomaly" or index 0. How about just run in the cmd window:
[tt] [blue]C:..>[/blue]ipconfig.exe[blue][hard enter][/blue][/tt]
to see it for yourself?
 
tsuji --

1) My initial thought was that it was an anomoly in 2000, but it's probably just a feature change in WMI. Compare the differences when running script-o-matic on a 2000 box vs. 2003. The index value is a unique identifier on each interface. On 2000 there are interface indicies 0-x, on 2003 the indicies are 1-x. Looking closely at the 2000 box you find that 0 is exactly the same as one of the other interfaces listed.

2) I'm not wild about parsing shell commands in VBS. It may be shorter, but it doesn't answer the question posed.

3) PHV was pointing phil in the right direction, but not giving the why.

I'm describing what I have observed. If I'm inaccurate, please tell me the what is right. The answer isn't always obvious.

[ponder]

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
[1] >I'm describing what I have observed.
Observation is one thing. Makeing a sense out of it is another. Maybe some other members can give you a confirmation of what you observe and what you conclude out of it.

[2] >I'm not wild about parsing shell commands in VBS.
Maybe you're not wild about it. Maybe I am not neither. But it is giving you the "right" direction to draw conclusion out of your observation from wmi script. If it is experimental science, it provides you with collateral evidence/support.

[3] If you're serious about observation, you've to observe by displaying all the property to make sure it is doubling up and in particular for windows 2000 specifically. What if you echo out the property DHCPEnabled as well, short of echoing out all the other properties? Maybe then you might conclude that it is not necessarily windows 2000 only.
 
How about
Code:
j = 0
For Each IPConfig in IPConfigSet
    j = j + 1
    if j = 1 then
        If Not IsNull(IPConfig.IPAddress) Then
            For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
                WScript.Echo IPConfig.IPAddress(i) & ", j=" & j
                WScript.Echo "Inside"
            Next
        End If
    End If
Next
It's a work around rather than a fix and it assumes you only ever want the first IP address returned (and therefore you're assuming there is only one)...

Note you should ensure that j is set back to 0 afterwards (if you're going to use this bit of code again).

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top