Sign in to follow this  
Followers 0
SIMPLE_XP

Need a better way to read NIC status

6 posts in this topic

I am trying to get a low CPU intensive way to read the status of Network cards. I am running a delayed internal function loop to keep the CPU from pegging, but making the check using a WMI call seems to eat up about 35% of the CPU when it makes the call.

I am using a DLL struct to check the AC vs. Battery, and was hoping there was a similar DLL call that could do the same thing for network cards...

Here is the code I have right now...

CODE
$wbemFlagReturnImmediately = 0x10

$wbemFlagForwardOnly = 0x20

$colItems = ""

$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

$colItems = $objWMIService.ExecQuery("SELECT * FROM BRCM_3RdPartyNetworkAdapter", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then

For $objItem In $colItems

If $objItem.Name = "Intel® PRO/Wireless 2200BG Network Connection" Then

$NIC_NAME = "Intel® PRO/Wireless 2200BG"

$NIC_CONNECTION_ID = $objItem.NetConnectionID

$NIC_TYPE = $objItem.NICType

If $objItem.Status = "OK" Then

$NIC_STATUS = "CONNECTED"

Else

$NIC_STATUS = "DISCONNECTED"

EndIf

ExitLoop

EndIf

Next

EndIf


Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF

Share this post


Link to post
Share on other sites



hmm, quick google search:

http://msdn2.microsoft.com/en-us/library/aa480679.aspx

not sure if it is helpful or not (or where to get the .dll it mentions) but it seems to be a nice idea..

have always wanted something like this myself, for when students un-plug the network cable, so it can lock kb/mouse input and show a message on screen, then remove that message when a student re-connects the cable

Share this post


Link to post
Share on other sites

hmm, quick google search:

http://msdn2.microsoft.com/en-us/library/aa480679.aspx

not sure if it is helpful or not (or where to get the .dll it mentions) but it seems to be a nice idea..

have always wanted something like this myself, for when students un-plug the network cable, so it can lock kb/mouse input and show a message on screen, then remove that message when a student re-connects the cable

Thanks, but I had already found that. I am not sure how to expose what I need. I am a little new to scripting... Hopefully somone can come up with something... I will keep looking.


Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF

Share this post


Link to post
Share on other sites

Thanks, but I had already found that. I am not sure how to expose what I need. I am a little new to scripting... Hopefully somone can come up with something... I will keep looking.

Um... sorry about that... :whistle: I thought I had found that example before, but it is different. It goes in to much more detail. I will take a look and if I find an easy way to use it I will post. Thanks!


Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF

Share this post


Link to post
Share on other sites

@SIMPLE_XP

In order to do this efficiently you will need to user the WMI event notifications

Look for "SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERETargetInstance ISA 'MSNdis_MediaConnectStatus"

I posted today an example of using the event notification in the example script.

Look for file monitor.

regards

ptrex

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks to ptrex's nudge in the right direction I was able to create a script to determine whether or not my laptop was currently docked based on whether the NIC in the docking station was present. Here is the code:

$strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\WMI")
    $nics = $objWMIService.InstancesOf("MSNdis_MediaConnectStatus",48)
    For $nic in $nics
        If $nic.InstanceName = "Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller" Then
            $Status = "Docked"
        EndIf
    Next

I am querying based on InstanceName only, but you use the NdisMediaConnectStatus property to determine whether the NIC is connected or not as well:

If $nic.InstanceName = "Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller"  AND $nic.NdisMediaConnectStatus = 0 Then
            MsgBox(4096,"",$nic.InstanceName & " is connected.")
EndIf

See here for more info.

Edited by sublimnl

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0