|
|
|||||||
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 [ 23. July 2003, 10:46: Message edited by: Raceeend ] |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
$Laptop = @wksta It shows all the NIC's just not the status. |
||||||||
|
|
|||||||
Maybe try this code. It works for me on my system. Give it a try and let me know.
|
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
This works for me at work, but not here at home. |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
I want to check if the NIC is disabled. I guess i have to do that with Win32_NetworkAdapter. |
||||||||
|
|
|||||||
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 ??? . 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 Thanks Rich |
||||||||
|
|
|||||||
maybe with some snmp scripting ? |
||||||||
|
|
|||||||
"Disabled" and "Unplugged" should be two different states. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
quote: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. |
||||||||
|
|
|||||||
Try Win32_NetworkConnection->ConnectionState quote:from the WMI SDK Documentation |
||||||||
|
|
|||||||
It's not working code:output: on a Win2k pro station (laptop)? @KIX 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 ] |