Windows Vista Forums

cable disconnected or connected
  1. #1


    Big D Guest

    cable disconnected or connected

    How can i determine if the LAN cable is connected or disconnected. I need to
    find out the status of a LAN connection for netcards. I know its not plugged
    in teh message state is media is disconnected.





      My System SpecsSystem Spec

  2. #2


    Tom Lavedas Guest

    Re: cable disconnected or connected

    On Jul 30, 10:57 am, "Big D" <BigDa...@xxxxxx> wrote:

    > How can i determine if the LAN cable is connected or disconnected. I need to
    > find out the status of a LAN connection for netcards. I know its not plugged
    > in teh message state is media is disconnected.
    Maybe something like this will do the job (based on a MS Technet
    Script Center example) ...

    aStatusStr = split("0,1,Connected,3,4,5,Disconnected,?", ",")

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

    Set cItems = oWMI.ExecQuery("Select * from Win32_NetworkAdapter"_
    & " where AdapterTypeID = 0") ' 0 = Ethernet 802.3

    For Each oItem in cItems
    if Instr(oItem.NetConnectionID, "Local Area Connection") > 0 then
    Wsh.Echo "Description: " & oItem.Description
    Wsh.Echo "Net Connection Status: " _
    & aStatusStr(oItem.NetConnectionStatus)

    End if
    Next

    I experimented to find that the status numbers 2 and 7 mean connected
    and disconnected, respectively. I don't have a reference that tells
    what the other possible states are or mean. That's why I populated
    the array with their numbers, instead. I also don't know what the
    highest possible value is.

    Tom Lavedas
    ===========
    http://members.cox.net/tglbatch/wsh/

      My System SpecsSystem Spec

  3. #3


    Alex K. Angelopoulos Guest

    Re: cable disconnected or connected

    I tracked down the status listings for this, Tom. For reference for anyone
    who uses this, here's the current MSDN listing:

    And here are the numeric codes, hex equivalents, and what they are supposed
    to mean.

    0 (hex &H0): Disconnected
    1 (hex &H1): Connecting
    2 (hex &H2): Connected
    3 (hex &H3): Disconnecting
    4 (hex &H4): Hardware not present
    5 (hex &H5): Hardware disabled
    6 (hex &H6): Hardware malfunction
    7 (hex &H7): Media disconnected
    8 (hex &H8): Authenticating
    9 (hex &H9): Authentication succeeded
    10 (hex &HA): Authentication failed
    11 (hex &HB): Invalid address
    12 (hex &HC): Credentials required

    "Tom Lavedas" <tglbatch@xxxxxx> wrote in message
    news:e3ae8251-7c47-427b-b2e9-606a6415f447@xxxxxx

    > On Jul 30, 10:57 am, "Big D" <BigDa...@xxxxxx> wrote:

    >> How can i determine if the LAN cable is connected or disconnected. I need
    >> to
    >> find out the status of a LAN connection for netcards. I know its not
    >> plugged
    >> in teh message state is media is disconnected.
    >
    > Maybe something like this will do the job (based on a MS Technet
    > Script Center example) ...
    >
    > aStatusStr = split("0,1,Connected,3,4,5,Disconnected,?", ",")
    >
    > strComputer = "."
    > Set oWMI = GetObject("winmgmts:" _
    > & "{impersonationLevel=impersonate}!\\" & strComputer _
    > & "\root\cimv2")
    >
    > Set cItems = oWMI.ExecQuery("Select * from Win32_NetworkAdapter"_
    > & " where AdapterTypeID = 0") ' 0 = Ethernet 802.3
    >
    > For Each oItem in cItems
    > if Instr(oItem.NetConnectionID, "Local Area Connection") > 0 then
    > Wsh.Echo "Description: " & oItem.Description
    > Wsh.Echo "Net Connection Status: " _
    > & aStatusStr(oItem.NetConnectionStatus)
    >
    > End if
    > Next
    >
    > I experimented to find that the status numbers 2 and 7 mean connected
    > and disconnected, respectively. I don't have a reference that tells
    > what the other possible states are or mean. That's why I populated
    > the array with their numbers, instead. I also don't know what the
    > highest possible value is.
    >
    > Tom Lavedas
    > ===========
    > http://members.cox.net/tglbatch/wsh/

      My System SpecsSystem Spec

  4. #4


    Pegasus \(MVP\) Guest

    Re: cable disconnected or connected


    "Tom Lavedas" <tglbatch@xxxxxx> wrote in message
    news:e3ae8251-7c47-427b-b2e9-606a6415f447@xxxxxx

    > On Jul 30, 10:57 am, "Big D" <BigDa...@xxxxxx> wrote:

    >> How can i determine if the LAN cable is connected or disconnected. I need
    >> to
    >> find out the status of a LAN connection for netcards. I know its not
    >> plugged
    >> in teh message state is media is disconnected.
    >
    > Maybe something like this will do the job (based on a MS Technet
    > Script Center example) ...
    >
    > aStatusStr = split("0,1,Connected,3,4,5,Disconnected,?", ",")
    >
    > strComputer = "."
    > Set oWMI = GetObject("winmgmts:" _
    > & "{impersonationLevel=impersonate}!\\" & strComputer _
    > & "\root\cimv2")
    >
    > Set cItems = oWMI.ExecQuery("Select * from Win32_NetworkAdapter"_
    > & " where AdapterTypeID = 0") ' 0 = Ethernet 802.3
    >
    > For Each oItem in cItems
    > if Instr(oItem.NetConnectionID, "Local Area Connection") > 0 then
    > Wsh.Echo "Description: " & oItem.Description
    > Wsh.Echo "Net Connection Status: " _
    > & aStatusStr(oItem.NetConnectionStatus)
    >
    > End if
    > Next
    >
    > I experimented to find that the status numbers 2 and 7 mean connected
    > and disconnected, respectively. I don't have a reference that tells
    > what the other possible states are or mean. That's why I populated
    > the array with their numbers, instead. I also don't know what the
    > highest possible value is.
    >
    > Tom Lavedas
    > ===========
    > http://members.cox.net/tglbatch/wsh/
    Nice code. Using your script plus the details supplied by Alex
    I found that the code failed on my laptop which uses a "Packet
    Scheduler Miniport" because this pseudo-adpater does not have
    the NetConnectionStatus property. The code below appears to
    overcome the problem:

    aStatusStr = Split("Disconnected,Connecting,Connected,Disconnecting," _
    & "Hardware not present,Hardware disabled,Hardware malfunction," _
    & "Media disconnected,Authenticating,Authentication succeeded," _
    & "Authentication failed,Invalid address,Credentials required", ",")

    Set oWMI =
    GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set cItems = oWMI.ExecQuery("Select * from Win32_NetworkAdapter"_
    & " where AdapterTypeID = 0") ' 0 = Ethernet 802.3

    For Each oItem In cItems
    If VarType(oItem.NetConnectionStatus) > 1 Then
    wsh.Echo "Description: " & oItem.Description
    wsh.Echo "Connection status: " & aStatusStr(oItem.NetConnectionStatus)
    End If
    WScript.echo
    Next



      My System SpecsSystem Spec

  5. #5


    Ruizz Guest

    Re: cable disconnected or connected

    all this is right... but this doesn't work on windows 2000 (property
    netConnectionStatus not availeble)

    any help will be nice

      My System SpecsSystem Spec

cable disconnected or connected problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed: Laptop screen goes black when HDMI cable is connected missmfarag General Discussion 4 10 Feb 2012
Easy Transfer connects & then shows disconnected cable TomJ Vista installation & setup 4 20 Aug 2009
Nic stat indicate disconnected cable Bruno Virtual Server 1 16 Jul 2008
Re: On startup PC restarts and network cable connected to PC problem PA Bear [MS MVP] Vista networking & sharing 0 22 Jun 2008
Can only get connected Wirelessly, but not with eithernet cable vicentejr28 Vista General 3 20 Oct 2007