Using VBScript to get back the Network Card's Location

Posted on 2008-11-05
Last Modified: 2013-11-09
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.
Question by:colinmussett
    LVL 63

    Expert Comment

    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


    for more info

    I hope this helps !

    Author Comment


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


    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.

    Author Comment


    i have attached an image with the informatin im trying to retreive, can anyone help with this ?
    LVL 38

    Accepted Solution

    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

    Open in new window


    Author Closing Comment

    thanks for that, worked perfectly and helped me along considrably.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
    #Citrix #Citrix Netscaler #HTTP Compression #Load Balance
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now