Page 1 of 1 1
Topic Options
#92504 - 2003-07-23 10:01 AM Finding NIC status
Raceeend Offline
Starting to like KiXtart

Registered: 2002-05-09
Posts: 129
Loc: The Netherlands
Hello,

I'm busy making a scripts which has to check the NIC status in a laptop. This is because sometimes when a user pulls out the NIC cable when the laptop is still shutting down the nic gets disabled. Which result in a call to the helpdesk and a lot of tests to see what is wrong.

This part of code i tried to check the status of the NIC but this is not returned. The description is working but not the status.
code:
? @KIX
$i = 0
For Each $Device In WMIQuery("DeviceID","Win32_NetworkAdapter",$Laptop)
$Status = WMIQuery("Status","Win32_NetworkAdapter",$Laptop)[$i]
$Description = WMIQuery("Description","Win32_NetworkAdapter",$Laptop)[$i]
? $Description+Chr(9)+$Status
$i = 1+$i
Next



[ 23. July 2003, 10:46: Message edited by: Raceeend ]
_________________________
regards, Martijn

Top
#92505 - 2003-07-23 10:12 AM Re: Finding NIC status
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
Where is the var $Laptop defined? I hope/assume it is somewhere else in the script!! If not, don't see how the code does anything.

May also want to change $i = 1+$i to $i=$i+1

Top
#92506 - 2003-07-23 10:14 AM Re: Finding NIC status
Raceeend Offline
Starting to like KiXtart

Registered: 2002-05-09
Posts: 129
Loc: The Netherlands
$Laptop = @wksta

It shows all the NIC's just not the status.
_________________________
regards, Martijn

Top
#92507 - 2003-07-23 10:27 AM Re: Finding NIC status
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
Maybe try this code. It works for me on my system.

Give it a try and let me know.





break on
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkConnection",,48)
For Each $objItem in $colItems
? "AccessMask: " + $objItem.AccessMask
? "Caption: " + $objItem.Caption
? "Comment: " + $objItem.Comment
? "ConnectionState: " + $objItem.ConnectionState
? "ConnectionType: " + $objItem.ConnectionType
? "Description: " + $objItem.Description
? "DisplayType: " + $objItem.DisplayType
? "InstallDate: " + $objItem.InstallDate
? "LocalName: " + $objItem.LocalName
? "Name: " + $objItem.Name
? "Persistent: " + $objItem.Persistent
? "ProviderName: " + $objItem.ProviderName
? "RemoteName: " + $objItem.RemoteName
? "RemotePath: " + $objItem.RemotePath
? "ResourceType: " + $objItem.ResourceType
? "Status: " + $objItem.Status
? "UserName: " + $objItem.UserName
Next


Top
#92508 - 2003-07-23 10:49 AM Re: Finding NIC status
Raceeend Offline
Starting to like KiXtart

Registered: 2002-05-09
Posts: 129
Loc: The Netherlands
Edited $Status = WMIQuery("Status","Win32_NetworkConnection",$Laptop)[$i] to $Status = WMIQuery("Status","Win32_NetworkAdapter",$Laptop)[$i]

But this is still not working.

Thanx for the code NTDOC but i need NetworkAdapter and if i use that in your code then it gets the same result: Not working.
_________________________
regards, Martijn

Top
#92509 - 2003-07-23 11:35 AM Re: Finding NIC status
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
This works for me at work, but not here at home.


; From this information
; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_networkadapter.asp
break on
$Index=0
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter",,48)
For Each $objItem in $colItems
$Index=$index+1
IF $objItem.AdapterType='Ethernet 802.3'
? 'Description: ' + $objItem.Description
? 'Adapter Type: ' + $objItem.AdapterType
? 'Name: ' + $objItem.Name
? 'Status: ' + $objItem.NetConnectionStatus
ENDIF
Next

Top
#92510 - 2003-07-23 01:19 PM Re: Finding NIC status
Raceeend Offline
Starting to like KiXtart

Registered: 2002-05-09
Posts: 129
Loc: The Netherlands
If i changes:
? 'Status: ' + $objItem.NetConnectionStatus

to:
? 'Status: ' + $objItem.Status

it works....on Winnt but not on w2k :-(

Could it be that the winnt comp has a static ip and the w2k dynamic? Or are there any other differences?
_________________________
regards, Martijn

Top
#92511 - 2003-07-23 02:26 PM Re: Finding NIC status
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
If you want to check if a network cable has been removed, you may want to check NetworkAdapterConfiguration instead.



Break On
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
For each $objItem in $colItems
  $aIPAddress = $objItem.IPAddress
  For Each $Address in $aIPAddress
      If Len($Address$Address ? EndIf
  Next
Next



If the cable is pulled, no device will have an IPAddress.

Top
#92512 - 2003-07-23 02:52 PM Re: Finding NIC status
Raceeend Offline
Starting to like KiXtart

Registered: 2002-05-09
Posts: 129
Loc: The Netherlands
I want to check if the NIC is disabled. I guess i have to do that with Win32_NetworkAdapter.
_________________________
regards, Martijn

Top
#92513 - 2003-07-24 11:44 AM Re: Finding NIC status
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 622
Loc: London, England
How can you check NIC is disabled, surly you wont get no responce.

How how can you tell the difference between NIC disabled and LAN Cable unplugged.

Unless the laptop has 2 NIC cards ??? [Smile] .

Correct me if I am wrong, just don't sound possible to me.

It would be like trying to write a script to check if a PC has been stolen, by checking it's NIC status [Big Grin]

Thanks

Rich

Top
#92514 - 2003-07-25 12:23 AM Re: Finding NIC status
Jochen Moderator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6288
Loc: Stuttgart, Germany
maybe with some snmp scripting ? [Roll Eyes]
_________________________



Top
#92515 - 2003-07-24 06:22 PM Re: Finding NIC status
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11161
Loc: Boston, MA, USA
"Disabled" and "Unplugged" should be two different states.
_________________________
There are two types of vessels, submarines and targets.

Top
#92516 - 2003-07-24 06:41 PM Re: Finding NIC status
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
That's why I made my suggestion. If the network cable gets unplugged the NIC will lose it's IP Address. I verified this on my PC.

BTW, my example is an exerpt from the Trigger Your Logon Script - WMI discussion.

Top
#92517 - 2003-07-25 11:24 AM Re: Finding NIC status
Raceeend Offline
Starting to like KiXtart

Registered: 2002-05-09
Posts: 129
Loc: The Netherlands
quote:
"Disabled" and "Unplugged" should be two different states.

That's what i think, but for now i don't even get a result when the nic is functioning. Have to search some more.
_________________________
regards, Martijn

Top
#92518 - 2003-07-25 05:04 PM Re: Finding NIC status
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11161
Loc: Boston, MA, USA
Try Win32_NetworkConnection->ConnectionState
quote:
Current state of the network connection.

Values are:
"Connected"
"Error"
"Paused"
"Disconnected"
"Connecting"
"Reconnecting"

from the WMI SDK Documentation
_________________________
There are two types of vessels, submarines and targets.

Top
#92519 - 2003-07-30 03:52 PM Re: Finding NIC status
Raceeend Offline
Starting to like KiXtart

Registered: 2002-05-09
Posts: 129
Loc: The Netherlands
It's not working

code:
? @KIX
$i = 0
For Each $Device In WMIQuery("DeviceID","Win32_NetworkAdapter","@WKSTA")
$Status = WMIQuery("ConnectionState","Win32_NetWorkConnection")[$i]
;if $Status = "Connected"
$Description = WMIQuery("Description","Win32_NetworkAdapter","@WKSTA")[$i]
? $Description+Chr(9)+$Status ;+Chr(9)+$i
;EndIf
$i = 1+$i
Next

output: on a Win2k pro station (laptop)
4.20
Infrared Port Connected
Infrared Modem Port Disconnected
RAS Async Adapter Disconnected
WAN Miniport (L2TP) Disconnected
WAN Miniport (PPTP) Connected
Direct Parallel
WAN Miniport (IP)
Intel(R) PRO/100 VE Network Connection
Deterministic Network Enhancer Miniport
Deterministic Network Enhancer Miniport

output: on a Winnt 4.0 Station

4.20
Intel(R) PRO/100 VM Network Connection [Bus 2 Slot 8] Connected

This is weird. That the LAN interface on the laptop doesn't show any state and the one in the NT machine does.

[ 30. July 2003, 15:53: Message edited by: Raceeend ]
_________________________
regards, Martijn

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
2 registered (Allen, ShaneEP) and 158 anonymous users online.
Newest Members
Sjaak, Biybucket, Markus1961, Ian231, kixnewbie12
17480 Registered Users

Generated in 0.044 seconds in which 0.017 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org