NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: Space
Looked for a script to check the NIC Speed setting but could not find one so I wrote this one.
I attempted to use WMI but the returned data was blank for my test systems.
AutoSense: was blank
Speed: was blank
This script attempts to determine what the current Network card Speed settings are set to.
This appears to work for all those involved in coding/testing but may not work for all systems. If you do test the code and find that it does not function correctly please post with some details so that we can attempt to make the code better.
NOTE: Code was updated to now support more NIC cards and operate against remote computers if you fill in the $sComputer value with the name of a remote computer.
Original Code NTDOC
Contributors Thanks for the help in completing this script
Glenn Barnas - Debugging, Code ideas
Bryce - Code ideas
Shawn - Code ideas, Testing
Les - Testing
Al - Testing
Examples of output are:
Device Name: Broadcom 570x Gigabit Integrated Controller
Device Index: 0001
Speed Setting: Auto
Media Type: 0
Device Name: Broadcom NetXtreme Gigabit Ethernet for hp
Device Index: 0007
Speed Setting: Auto
Media Type: 0
Device Name: HP NC7770 Gigabit Server Adapter
Device Index: 0000
Speed Setting: 100 Mb Full
Media Type: 4102
Device Name: HP NC7770 Gigabit Server Adapter
Device Index: 0006
Speed Setting: 100 Mb Full
Media Type: 4102
Device Name: HP NC7781 Gigabit Server Adapter
Device Index: 0002
Speed Setting: Undetermined probably 1000 Full
Media Type: 8
Device Name: HP NC7781 Gigabit Server Adapter
Device Index: 0003
Speed Setting: Undetermined probably 1000 Full
Media Type: 8
Device Name: Intel(R) PRO/100 VM Network Connection
Device Index: 0002
Speed Setting: Auto Detect
Media Type: 0
Device Name: Intel(R) PRO/100+ Management Adapter
Device Index: 0007
Speed Setting: Auto Detect
Media Type: 0
Device Name: Linksys LNE100TX Fast Ethernet Adapter(LNE100TX v4)
Device Index: 0001
Speed Setting: AutoSense
Media Type: 0
Device Name: 3Com Gigabit LOM (3C940)
Device Index: 0010
Speed Setting: Auto
Media Type: Autoselect
Device Name: AMD PCNET Family PCI Ethernet Adapter
Device Index: 0001
Speed Setting: Auto Detect
Media Type: 0
Device Name: HP NC7770 Gigabit Server Adapter
Device Index: 0000
Speed Setting: 1000 Mb Full
Media Type: 8200
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11634
Loc: Space
Okay, here is a quickie UDF to test it out and provide feedback before Glenn posts it in the UDF forum.
Let us know what you think or any other questions you may have about it.
Code:
Break On Dim $SO,$Pause $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $SO=SetOption('WrapAtEOL','On')
Dim $Array, $X, $Y ; Declare the COMPUTER var if not defined on the command line If Not IsDeclared($COMPUTER) Global $COMPUTER EndIf $Array = NicInfo($COMPUTER) If UBound($Array) < 0 @SERROR ? Else UBound($Array) ' elements returned.' ? For $X = 0 to UBound($Array) For $Y = 0 to UBound($Array[$X]) $y '. ' $Array[$X][$Y] ? Next Next EndIf
Code:
;;====================================================================== ;; ;;FUNCTION NicInfo() ;; ;;ACTION Returns an array NIC information ;; ;;AUTHOR Glenn Barnas / NTDoc ;; ;;VERSION 1.0 ;; ;;DATE CREATED 2005/03/17 ;; ;;DATE MODIFIED ;; ;;SYNTAX NicInfo(target) ;; ;;PARAMETERS target - name of sysetm to query ;; ;;REMARKS Array of arrays is returned - a collection of arrays for each physical or virtual NIC ;; WAN/RAS, and Miniport drivers are ignored ;; ;;RETURNS Array of Arrays ;; ;;DEPENDENCIES none ;; ;;TESTED WITH NT4, W2K, WXP ;; ;;EXAMPLES $Array = NicInfo($COMPUTER) ;; ;; If UBound($Array) < 0 ;; @SERROR ? ;; Else ;; ;; UBound($Array) ' elements returned.' ? ;; ;; For $X = 0 to UBound($Array) ;; For $Y = 0 to UBound($Array[$X]) ;; $y '. ' $Array[$X][$Y] ? ;; Next ;; Next ;; EndIf ;; ; Function NicInfo(OPTIONAL $Target)
Dim $Regkey, $SubKeyCounter, $NicArray, $CurrentSubKey, $Index Dim $Name, $Key, $WorkRegKey, $SubKey
; Insure $Target uses the format "\\target\" if specified $Target = IIf($Target <> '', '\\' + Join(Split($Target, '\'), '', 3) + '\', '')
; init the enumeration index and array index $SubKeyCounter = 0 $Index = 0
; Enumerate all of the keys that are LAN adapters $CurrentSubKey = EnumKey($RegKey, $SubKeyCounter) If @ERROR Exit @ERROR ; exit now if can't read registry! EndIf
$CurrentSubKey = EnumKey($RegKey, $SubKeyCounter) While @ERROR = 0 $Key = ReadValue($RegKey + '\' + $CurrentSubKey, 'Characteristics') If $Key = 132 Or $Key = 32769 ; physical nic or virtual team ReDim Preserve $NicArray[$Index] ; increase the array size $NicArray[$Index] = $CurrentSubKey ; add the subkey to the array $Index = $Index + 1 ; increment the array index EndIf $SubKeyCounter = $SubKeyCounter + 1 ; increment the enumeration index $CurrentSubKey = EnumKey($RegKey, $SubKeyCounter) ; get the next key Loop
; Have an array of all the NIC subkeys now... Gather some appropriate data on each Dim $NicData[UBound($NicArray)]
$Index = 0 Dim $WorkArray[14] For Each $SubKey In $NicArray ; Start by determining the Speed/Duplex value name $SubKeyCounter = 0 $Name = '' $WorkRegKey = $RegKey + '\' + $SubKey + '\Ndi\Params'
; Enumerate all of the subkeys to locate the Speed/Duplex value name $CurrentSubKey = EnumKey($WorkRegKey, $SubKeyCounter) While @ERROR = 0 And $Name = '' $Key = ReadValue($WorkRegKey + '\' + $CurrentSubKey, 'ParamDesc') If InStr($Key, 'Duplex') Or InStr($Key, 'Connection Type') $Name = $CurrentSubKey ; Save the Key Name EndIf $SubKeyCounter = $SubKeyCounter + 1 ; increment the enumeration index $CurrentSubKey = EnumKey($WorkRegKey, $SubKeyCounter) ; get the next key Loop ; enumerate subkeys
; Collect the data for this adapter $WorkArray[0] = ReadValue($RegKey + '\' + $SubKey, 'DriverDesc') ; Adapter Description $WorkArray[1] = ReadValue($RegKey + '\' + $SubKey, 'ProviderName') ; Manufacturer $WorkArray[2] = ReadValue($RegKey + '\' + $SubKey, 'NetCfgInstanceId') ; NIC GUID $WorkArray[3] = ReadValue($RegKey + '\' + $SubKey, $Name) ; Speed/Duplex value $WorkArray[4] = ReadValue($WorkRegKey + '\' + $Name + '\Enum', $WorkArray[3]) ; Speed/Duplex text $WorkArray[5] = ReadValue($RegKey + '\' + $SubKey, 'DriverVersion') ; Driver Version
; handle an undefined speed/duplex setting If $WorkArray[4] = '' $WorkArray[4] = 'Undefined' EndIf ; undefined speed
; Special values for Compaq/HP Team If ReadValue($RegKey + '\' + $SubKey, 'Characteristics') = 32769 $WorkArray[10] = 'HPTEAM' ; special flag $WorkArray[11] = ReadValue($RegKey + '\' + $SubKey, 'TeamAdapters') ; # of adapters in team $WorkArray[12] = ReadValue($RegKey + '\' + $SubKey, 'TeamInstances') ; ID of adapters in team EndIf
$NicData[$Index] = $WorkArray $Index = $Index + 1
ReDim $WorkArray[14]
Next ; CurrentSubKey
; Return the array of arrays ReDim Preserve $NicData[$Index - 1] $NicInfo = $NicData
EndFunction
; Read a String_Multi_SZ val and return a space-delimited string Function ReadStringValue($Key, $Val) $ReadStringValue = Trim(Join(Split(ReadValue($Key, $Val), '|'), ' ')) EndFunction