Change NIC speed/duplex settings in script?

30,829

It seems like this is a vendor-specific setting, as noted in a technet thread Here

It notes that making a registry change to the NIC's key under HKLM\SYSTEM\CurrentControlSet\Control\Class\(GUID)\(INTNUM)\(Vendor-specific-registrykey) should be enough, but I think you should also add something in there to disable then reenable the NIC when changing it.

Here's an example Batch script that incorporates all of the above with the template in the question.

@echo off  
reg add HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001 /v RequestedMediaType /d 6 /t REG_SZ /f  
netsh interface set interface "Local Area Connection" DISABLED  
netsh interface set interface "Local Area Connection" ENABLED  
echo Connection set to 100 Mb/Full Duplex  
echo Press any key to change back to Auto  
PAUSE  
reg add HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001 /v RequestedMediaType /d 0 /t REG_SZ /f  
netsh interface set interface "Local Area Connection" DISABLED  
netsh interface set interface "Local Area Connection" ENABLED  
echo Connection set to Auto  
echo Press any key to exit  
PAUSE  

To make the above script work for you, the following may need to be changed.

  • Everything after "\Class\" in the registry key may need to be changed to match the appropriate key in your system. Look for a key starting in {4D36E972 and work from there to find the one you need.
  • The parameters for the /v, /d, and /t switches should be set to match the vendor-specific configuration for your system.
  • Change "Local Area Connection" if necessary, to match the name of the interface you are working on.

As always, be sure to make a full backup of the Registry before attempting any untested changes.    

Share:
30,829

Related videos on Youtube

Iszi
Author by

Iszi

This is a canary message, to be removed in the case of my death. If you're reading this, I haven't died yet. Then again, how would you know? I mean, how could I possibly delete this message after my own demise? You know what? Just go ahead and assume I'm dead. Any posts appearing to be made by me are from an impostor who's stolen my identity post-mortem, and only further prove the fact that I am dead. After all, why would I even think to post a canary message if I was expecting to be alive to remove it anyway? In any case, I'm still not the droid you're looking for.

Updated on September 17, 2022

Comments

  • Iszi
    Iszi over 1 year

    I have a laptop running Windows Server 2003 SP2, with PowerShell installed.

    Occasionally, this system has to be used in environments where it needs the NIC manually set to 100 Mbps/Full Duplex in order to function correctly. In most other environments, this needs to be set to Auto-detect for best performance.

    Normally, I do this through the following procedure:

    • Right-click My Network Places, select Properties.
    • Right-click Local Area Connection, select Properties
    • Click Configure
    • On the Advanced tab, select the Speed & Duplex property and change the Value from Auto to 100 Mb Full.
    • Reverse the change when done with work.

    Is there a way to do this via Batch or PowerShell scripting? I'm looking to do something like this:

    @ECHO OFF
    [Insert 100 Mbps/Full Duplex commands here]
    ECHO NIC set to 100 Mbps/Full Duplex
    ECHO Press any key to return to Auto-Detect
    PAUSE
    [Insert Auto-Detect commands here]
    ECHO NIC returned to Auto-Detect
    ECHO Press any key to exit
    PAUSE

    I've been told there may be some methods to do this via WMIC or PowerShell, but I haven't been able to find the proper switches, values, or syntax.

  • Iszi
    Iszi about 13 years
    Took some doing, but I finally found the keys I needed, and got everything together with the info here.