delphinetwork-programmingdelphi-10.3-riodisablendis

How programatically disable specific item in network connection properties?


I want to know if some API/code exists to disable a specific item in the (current) network connection properties?

image

If yes, could you show a working code example, explain the details, and point out some limitations (if they exist) of the technique used?


Solution

  • The API to disable these bindings is INetCfgBindingPath::Enable. The bindview sample illustrates how to call the API.

    From Windows 8 and later, you may alternatively invoke the WMI method /root/standardcimv2/MSFT_NetAdapterBindingSettingData::Disable. Here's a line of PowerShell that illustrates how to disable the bindings from a NIC named "mb-port" to the "ms_msclient" driver (aka wkssvc):

    Get-CimInstance -Namespace root/standardcimv2 -Query 'SELECT * FROM MSFT_NetAdapterBindingSettingData WHERE Name = "mb-port" AND ComponentID = "ms_msclient"' | Invoke-CimMethod -MethodName Disable
    

    Note that the GUI is being sneaky: it merges multiple bindpaths into the same checkbox. In the example you have highlighted, there are likely 2 bindpaths from ms_msclient to the NIC: one over IPv4 and one over IPv6. The GUI disables/enables all paths when you clear/tick the checkbox. If you come in through the API and want to do the same, you'll need to enumerate all bindpaths that start from ms_msclient and go to the NIC mb-port.