nrlewis
-
Total Posts
:
47
- Scores: 0
-
Reward points
:
0
- Joined: 10/16/2008
-
Status: offline
|
Win32_NetworkAdapter::NetConnectionStatus
Monday, November 28, 2011 9:19 AM
( permalink)
I've encountered a strange issue. I'm testing this script on Windows 7. If the network cable is plugged in, the message is displayed, and the program terminates. If the network cable is unplugged, nothing happens. The script runs for a few seconds, but it terminates without any notifications...any thoughts? strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter Where NetConnectionStatus=2") For Each objProps in colItems If objProps.NetConnectionStatus = 2 Then wscript.echo "Cable Detected." wscript.quit Else While objProps.NetConnectionStatus <> 2 wscript.echo " Connect the network cable..." WEnd wscript.echo "Network Cable Detected." End If Next Thanks in advance!
<message edited by nrlewis on Monday, November 28, 2011 9:30 AM>
|
|
|
|
59cobalt
-
Total Posts
:
981
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: offline
|
Re:Win32_NetworkAdapter::NetConnectionStatus
Monday, November 28, 2011 10:59 AM
( permalink)
The objects in colItems represent the status from when you run the query. They do not automagically pick up changes that happen afterwards. You need to re-query the connection status to detect a change.
|
|
|
|
nrlewis
-
Total Posts
:
47
- Scores: 0
-
Reward points
:
0
- Joined: 10/16/2008
-
Status: offline
|
Re:Win32_NetworkAdapter::NetConnectionStatus
Tuesday, November 29, 2011 3:18 AM
( permalink)
59cobalt The objects in colItems represent the status from when you run the query. They do not automagically pick up changes that happen afterwards. You need to re-query the connection status to detect a change. But this code yields the same results: the script terminates without echoing the message. Could it be because the query isn't finding any results, so there is nothing for the FOR statement to do? If so, is there any way to capture the NULL query? strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter Where NetConnectionStatus=2")
For Each objProps in colItems
If objProps.NetConnectionStatus <> 2 Then
wscript.echo "-1" End If Next
|
|
|
|
59cobalt
-
Total Posts
:
981
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: offline
|
Re:Win32_NetworkAdapter::NetConnectionStatus
Tuesday, November 29, 2011 11:26 AM
( permalink)
Umm... when you issue a query that returns only results with NetConnectionStatus=2 it's kinda unsurprising that you won't find any results with NetConnectionStatus<>2 among them.
|
|
|
|