Using VBScript to get back the Network Card's Location

I need to identify the slot and port number of a NIC within a machine, this is because the machines in question have 8-10 NIC's depending on the machines requirements. I want to automate the renaming and static IP allocation on each adapter in a machine from an excel sheet/database without using the MAC.
Any help appreciated.
colinmussettTAAsked:
Who is Participating?
 
Shift-3Connect With a Mentor Commented:
Paste the script below into a text file with a .vbs extension.  Running it will echo the name and location of each hardware NIC in the machine.

If you'd like it to read directly from an Excel sheet please provide an example and more detail about how you'd like it to work.



Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
 
On Error Resume Next
 
Set objShell=CreateObject("WScript.Shell")
 
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
 
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter")
 
For Each objItem In colItems
    strName = objItem.Name
    strID = objItem.PNPDeviceID
    strKey = "SYSTEM\CurrentControlSet\Enum\" & strID
    objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey, "LocationInformation", strLoc
    If strLoc Then
        WScript.Echo strName & " - " & strLoc
    End If
Next

Open in new window

0
 
SysExpertCommented:
I do not think that this info is available easily, but check the program calle PCIinfo or similar ( DOS I think ) as it may be helpful

see

http://members.datafast.net.au/dft0802/other.htm

for more info


I hope this helps !
0
 
colinmussettTAAuthor Commented:

I have been searching the registry and found the reference in the registry here:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\PCI\VEN_14E4&DEV_170C&SUBSYS_02291028&REV_02\4&37cf71d4&0&00F0\LocationInformation

The value reads:

@system32\\drivers\\pci.sys,#65536;PCI bus %1, device %2, function %3;(3,0,0)

the numbers in the brackets being what im interested in, but need to be able to link this back to the network interface card, the above being just one of the NIC's and I have 8 in the machine.

Help appreciated.
0
 
colinmussettTAAuthor Commented:

i have attached an image with the informatin im trying to retreive, can anyone help with this ?
network-card.png
0
 
colinmussettTAAuthor Commented:
thanks for that, worked perfectly and helped me along considrably.
regards
colin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.