Solved Find NIC Class GUID in batch script using wmic (or anything else)


shoober420

Active member
Member
Local time
4:44 AM
Posts
127
OS
Windows 11 27783
Ive discovered that you can get device IDs from registry using wmic and shell scripting commands.
for /f %%i in ('wmic path Win32_USBController get PNPDeviceID^| findstr /l "PCI\VEN_"') do (
Thats for the USB controller as an example. Im trying to figure out how to apply a similar method for getting the Class GUID for the NIC to change this registry key. In bold is the NIC Class GUID.
reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\1B2AF3AC-865B-4B81-BFFA-790A51C634A6}" /v "TCPNoDelay" /t REG_DWORD /d "1" /f
The NIC Class GUID can be found manually by:
Device Manager > Network adapters > Properties > Details tab

The reason for wanting this script is so the Class GUID doesnt need modified within the batch script to correlate with the randomly generated Class GUID for each system, as it always changes depending on NIC.

Any thoughts?
 
Windows Build/Version
Windows 11 27729

My Computer

System One

  • OS
    Windows 11 27783
    Computer type
    PC/Desktop
    CPU
    Intel i7 7700 @4.0ghz
    Memory
    64gb DDR4
    Graphics Card(s)
    Radeon RX 5500 XT
    Other Info
    https://www.github.com/shoober420
WMIC is now deprecated, meaning it's not enabled by default in 24H2 and will disappear in the next Windows release. So you should try learning PowerShell in the near future.

But here's the old fashioned way:
Code:
for /f %%n in ('wmic nic where "GUID is not null" get Name^,GUID ^| findstr "Realtek PCIe"') do (
   reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\%%n" /v TCPNoDelay /t REG_DWORD /d 1 /f       
)

Device ID's are enumerated as randomly created GUID's (Globally Unique Identifiers). A Class ID would be something that's always static, so be careful with the terminology.
 

My Computer

System One

  • OS
    Windows 7
PowerShell method:
Code:
$GUID = (Get-NetAdapter -Name *Ethernet*).DeviceID
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\$GUID" -Name "TCPNoDelay" -Value 1 -Force
 

My Computer

System One

  • OS
    Windows 7
Very nice, that makes things easier when executing this script on another machine. If I wanted to do the same with the following registry key:

reg add "HKLM\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcpip_{1B2AF3AC-865B-4B81-BFFA-790A51C634A6}" /v "NetbiosOptions" /t REG_DWORD /d "2" /f
Would I simply do:

for /f %%n in ('wmic nic where "GUID is not null" get Name^,GUID ^| findstr "Realtek PCIe"') do (
reg add "HKLM\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcpip_%%n" /v NetbiosOptions /t REG_DWORD /d 2 /f
)
Or is this wrong? It looks like the "Tcpip_%%n" might not work correctly.
 

My Computer

System One

  • OS
    Windows 11 27783
    Computer type
    PC/Desktop
    CPU
    Intel i7 7700 @4.0ghz
    Memory
    64gb DDR4
    Graphics Card(s)
    Radeon RX 5500 XT
    Other Info
    https://www.github.com/shoober420
1. Don't forget to replace the findstr expression match with whatever your network device's descriptive name.

2. %%n will be substituted in-line. CMD isn't bothered by the "_" before the variable. Where the script would fail is if the wmic query returns anything other than exactly one result (meaning zero matches, or two or more matches). In that case, you would need more safety logic. But if you know the findstr will always return one unique match, it's acceptable to keep the script easier to read.
 

My Computer

System One

  • OS
    Windows 7
Thats a relief. I do have a Marvell AQtion NIC, so ill have to adjust accordingly. If I were to use "*" for "findstr", would it apply to all NICs on the machine and any NIC found on other machines (wireless and wired)?
 

My Computer

System One

  • OS
    Windows 11 27783
    Computer type
    PC/Desktop
    CPU
    Intel i7 7700 @4.0ghz
    Memory
    64gb DDR4
    Graphics Card(s)
    Radeon RX 5500 XT
    Other Info
    https://www.github.com/shoober420
If you have multiple NIC's (like a laptop), then you need to turn this into a loop to skip over the WMIC output's header line.
Code:
for /f "delims=" %%n in ('wmic nic where "GUID is not null" get guid ^| findstr /v GUID') do (
   reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\%%n" /v TCPNoDelay /t REG_DWORD /d 1 /f  
   reg add "HKLM\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcpip_%%n" /v NetbiosOptions /t REG_DWORD /d 2 /f
)
 

My Computer

System One

  • OS
    Windows 7
Truly appreciate it, now I can run this script on any machine and it will apply the settings to any NIC.
 

My Computer

System One

  • OS
    Windows 11 27783
    Computer type
    PC/Desktop
    CPU
    Intel i7 7700 @4.0ghz
    Memory
    64gb DDR4
    Graphics Card(s)
    Radeon RX 5500 XT
    Other Info
    https://www.github.com/shoober420

Latest Tutorials

Back
Top Bottom