SIMPLE_XP Posted March 11, 2007 Posted March 11, 2007 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
tAKTelapis Posted March 12, 2007 Posted March 12, 2007 hmm, quick google search:http://msdn2.microsoft.com/en-us/library/aa480679.aspxnot 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
SIMPLE_XP Posted March 12, 2007 Author Posted March 12, 2007 hmm, quick google search:http://msdn2.microsoft.com/en-us/library/aa480679.aspxnot 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 cableThanks, 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
SIMPLE_XP Posted March 12, 2007 Author Posted March 12, 2007 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... 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
ptrex Posted March 12, 2007 Posted March 12, 2007 @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 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
sublimnl Posted June 15, 2007 Posted June 15, 2007 (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 NextI 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.") EndIfSee here for more info. Edited June 15, 2007 by sublimnl
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now