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


Break On

Dim $SO,$Pause
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('WrapAtEOL','On')


; Main code (function) starts here...
DIM $Index, $BadAdapters, $Type, $Types, $Speed, $Name, $sComputer
DIM $HKLMSCCSCC, $NicData, $Key, $DeviceID, $MediaType, $RequestedMediaType


; Enter the name of the remote computer here, if left blank will check current Computer
$sComputer=''


; Add UNC to Computer name if $sComputer name supplied
If $sComputer $sComputer = '\\' + $sComputer + '\' EndIf
If InStr($sComputer,@WKSTA) $sComputer="" EndIf


; List of adapter names that are not NICs. Any name that ends with a (val)
; will be trimmed to eliminate the parens and the data in them.
$BadAdapters = '~Miniport Wan~RAS Async~Direct Parallel~'


; Main registry key to enumerate
$HKLMSCCSCC=$sComputer+'HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}'


; Get a list of NICs from the registry
$NicData = ArrayEnumKey($HKLMSCCSCC)


; Examine each entry
For Each $Key In $NicData


; Read the Driver Description
$DeviceID = ReadValue($HKLMSCCSCC+'\'+$Key,'DriverDesc')


; If not null, and not in the list of Bad Adapters, try to identify the speed parameter
If $DeviceID And Not InSTR($BadAdapters, '~' + Trim(Split($DeviceID, '(')[0]) + '~')


Select
; Intel adapters
Case InStr($DeviceID,'Intel')
$Name='SpeedDuplex'


; Broadcom and HP adapters
Case InStr($DeviceID,'Broadcom') Or InStr($DeviceID,'HP NC7781')
Or InStr($DeviceID,'HP NC7770')
$Name='RequestedMediaType'


; 3Com adapters
Case InStr($DeviceID,'3Com')
$Name='media_type'


; HP Realtek adapters
Case InStr($DeviceID,'Realtek')
$Name='DuplexMode'


; Linksys adapters
Case InStr($DeviceID,'Linksys')
$Name='MediaType'


; Virtual WMware ESX Server adapters
Case InStr($DeviceID,'AMD PCNET')
$Name='EXTPHY'


; HP NC3163 adapters
Case InStr($DeviceID,'HP NC3163')
$Name='SpeedDuplex'


; Unable to find one of the listed nic cards
Case 1
$Name = ''
EndSelect


; If we identified the card, read & display the settings
If $Name
; Read the numeric value that represents the current Speed / Duplex setting
$RequestedMediaType = ReadValue($HKLMSCCSCC+'\' + $Key, $Name)


; If this value is blank, we probably don't have a valid NIC definition
; continue if not blank
If $RequestedMediaType <> ''


; Enumerate the values that represent the Speed/Duplex setting descriptions
$Types = ArrayEnumValue($HKLMSCCSCC + '\' + $Key + '\Ndi\params\' + $Name + '\enum')


; Should always be an array ?
If VarType($Types) >= 8192


; Find the descriptive value that matches our defined setting
$Index = AScan($Types, $RequestedMediaType)


; Then get the speed/duplex description string if Index is valid
If $Index >= 0
$Types = $Types[$Index]
$Speed = ReadValue($HKLMSCCSCC+'\' + $Key + '\Ndi\params\' + $Name + '\enum', $Types)
Else
; Value defined does not match avaialble descriptions
$Speed = 'Undetermined'
If $RequestedMediaType = 8 $Speed = 'Possible Gigabit Full Duplex' EndIf
EndIf ; Good index
Else
; Not an array, so no setting names were defined
$Speed = 'Undetermined - bad array'
EndIf ; Is array


'Device Name: ' $DeviceID ?
'Device Index: ' $Key ?
'Speed Setting: ' $Speed ?
'Media Type: ' $RequestedMediaType ?


EndIf ; Requested Media Type


EndIf ; Valid name


EndIf ; Good device id


Next ; Each Entry


; Return an array of subkey names from the primary location
Function ArrayEnumKey($RegSubKey)
Dim $SubKeyCounter, $CurrentSubKey, $SubKeyArray
If Not KeyExist($RegSubKey)
Exit 87
EndIf
$SubKeyCounter = 0
Do
$CurrentSubKey = EnumKey($RegSubKey, $SubKeyCounter)
If Not @ERROR
ReDim Preserve $SubKeyArray[$SubKeyCounter]
$SubKeyArray[$SubKeyCounter] = $CurrentSubKey
$SubKeyCounter = $SubKeyCounter + 1
EndIf
Until @ERROR
$ArrayEnumKey = $SubKeyArray
Exit 0
EndFunction


; Return an array of values from the defined key
Function ArrayEnumValue($RegSubKey)
DIM $ValueCounter, $CurrentValue, $ValueArray
If Not KeyExist($regsubkey)
Exit 87
EndIf
$ValueCounter = 0
Do
$currentvalue=EnumValue($RegSubKey,$ValueCounter)
If Not @ERROR
ReDim Preserve $ValueArray[$ValueCounter]
$ValueArray[$ValueCounter] = $CurrentValue
$ValueCounter = $ValueCounter + 1
EndIf
Until @ERROR
$ArrayEnumValue = $ValueArray
Exit 0
EndFunction




Edited by NTDOC (2005-03-17 09:44 AM)