Win32_NetworkAdapter::NetConnectionStatus

Author Message
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)
0
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>
 
#1
    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)
    0
    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.
     
    #2
      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)
      0
      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 

       
       
      #3
        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)
        0
        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.
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9