Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - cable disconnected or connected

Reply
 
Old 07-30-2008   #1 (permalink)
Big D


 
 

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
Old 07-30-2008   #2 (permalink)
Tom Lavedas


 
 

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.
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
Old 07-30-2008   #3 (permalink)
Alex K. Angelopoulos


 
 

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 SpecsSystem Spec
Old 07-31-2008   #4 (permalink)
Pegasus \(MVP\)


 
 

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/
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
Old 09-26-2008   #5 (permalink)
Ruizz


 
 

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
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46