Get active network adapters from registry

  • Thread starter Thread starter Petr Laznovsky
  • Start date Start date
P

Petr Laznovsky

I want to read info about ACTIVE network connections from registry by
batch file. Trying read and parse

"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards"

and

"HKLM\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%servicename%\connection"


path, but there are also information about installed and currently not
presented (disconnected) USB network devices. Is there any way to get
only present adapters? there is no such information in this reg key. I
have only idea to parse adapter list get from registry against output of
ipconfig command which show only presented adapters, but this is all
thumbs.
Better idea??

Script should be distributable over W2k+ systems


P.L.
 
Petr Laznovsky said:
I want to read info about ACTIVE network connections from registry by
batch file. Trying read and parse

"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards"

and

"HKLM\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%servicename%\connection"

path, but there are also information about installed and currently not
presented (disconnected) USB network devices. Is there any way to get only
present adapters? there is no such information in this reg key. I have
only idea to parse adapter list get from registry against output of
ipconfig command which show only presented adapters, but this is all
thumbs.
Better idea??

Script should be distributable over W2k+ systems


P.L.

When you match the data for DeviceInstanceID against strings found in the
output from the command

devcon hwids "*"

then you should be able to identify your active adapters. You can download
devcon.exe from
http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe.
Note also that instead of examining

"HKLM\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%servicename%\connection"
you should examine
"HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%servicename%\connection"
 
Petr Laznovsky said:
The batch should be distributable autonomously, without any additional
utilities. Pure shell script.

P.L.

Why not obain the information from the output of ipconfig? Alternatively you
could use WMI as in the script below:

'------------------------------------------
'Display the status of all network adapters
'15.8.2009 FNL
'------------------------------------------
iEthernet = 0: iWireless = 9
aStatus = Split("Disconnected/Connecting/Connected/Disconnecting/" _
& "Hardware not present/Hardware disabled/Hardware malfunction/" _
& "Media disconnected/Authenticating/Authentication succeeded/" _
& "Authentication failed", "/")
iEthernet = 0
iWireless = 9
Set oWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = oWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapter",,48)
For Each oItem In colItems
If (oItem.AdapterTypeId = iEthernet _
Or oItem.AdapterTypeId = iWireless) _
And Not IsNull(oItem.NetConnectionStatus) _
Then WScript.Echo oItem.Name & ": ", aStatus(oItem.NetConnectionStatus)
Next
 
Back
Top