1

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?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

1 Answers1

3

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.

Jeffrey Tippet
  • 3,146
  • 1
  • 14
  • 15
  • i have a doubt: Saw a [program example](https://stackoverflow.com/a/18473911/9708179) where you call [`INetCfg::Apply`](https://learn.microsoft.com/en-us/previous-versions/windows/hardware/network/ff547947(v=vs.85)) after [`INetCfgBindingPath::Enable`](https://learn.microsoft.com/en-us/previous-versions/windows/hardware/network/ff547700(v=vs.85)). This is really mandatory to disable the binding? – FLASHCODER Jun 10 '21 at 22:18
  • I'm using [this](https://superuser.com/a/1524965) vbscript to list and disable (`objItem.Disable`), but seems that theres not possibility of "`objItem.Apply`". – FLASHCODER Jun 10 '21 at 22:32
  • INetCfg and MSFT_NetAdapterXxx are different APIs with different designs. The WMI one is not transactional, so it does not require any sort of `Apply`. – Jeffrey Tippet Jun 12 '21 at 04:37