![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | Re: cable disconnected or connected On Jul 30, 10:57 am, "Big D" <BigDa...@xxxxxx> wrote: Quote: > 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. 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 Specs![]() |
| | #3 (permalink) |
| | 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 Quote: > On Jul 30, 10:57 am, "Big D" <BigDa...@xxxxxx> wrote: Quote: >> 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 Specs![]() |
| | #4 (permalink) |
| | Re: cable disconnected or connected "Tom Lavedas" <tglbatch@xxxxxx> wrote in message news:e3ae8251-7c47-427b-b2e9-606a6415f447@xxxxxx Quote: > On Jul 30, 10:57 am, "Big D" <BigDa...@xxxxxx> wrote: Quote: >> 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/ 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Easy Transfer connects & then shows disconnected cable | Vista installation & setup | |||
| Nic stat indicate disconnected cable | Virtual Server | |||
| Re: On startup PC restarts and network cable connected to PC problem | Vista networking & sharing | |||
| Can only get connected Wirelessly, but not with eithernet cable | Vista General | |||
| Connection is offered , dial up and broadband, thru modem, when I´m actually connected by cable... | Vista General | |||