How to change the binding order of network adapters programaticall

Discussion in 'Windows Vista Drivers' started by Juan Morato, May 3, 2006.

  1. Juan Morato

    Juan Morato Guest

    I am trying to look for a way to change the binding order of network
    adapters in Windows XP programmaticaly.
    I'm already checked out, and
    what I do is
    1 - acquire a write lock using
    2 - enumerate all the components
    3 - search for the component I want to put on the top of the list.
    4 - enumerate all the binding paths for the component
    5 - for each binding path I try to call
    with NULL as the second argument.
    but it gives me E_INVALIDARG
    And here is where I stuck :-(

    I have the latest Windows XP DDK downloaded from MSDN.

    Can anyone give me any suggestion what may be the cause for the error?
    May be the null as second parameter?
    What do i do if I can not pass null as the second argument to MoveBefore?

    Next is my code. Thanks in advance.

    HRESULT NetCfgAPI::SetPrimaryNetworkAdapter(INetCfg* pNetCfg,LPWSTR
    LPWSTR displayName = NULL;
    INetCfgClass* pNetCfgClass = NULL;
    INetCfgComponent* pNetCfgComp = NULL;
    INetCfgBindingPath* pNetCfgBind = NULL;
    IEnumNetCfgComponent* pEnumComp = NULL;
    IEnumNetCfgBindingPath* pEnumBind= NULL;
    NetCfgComponentBindings* pNetCfgCompBind = NULL;

    hr = this->HrGetComponentEnum(pNetCfg, &GUID_DEVCLASS_NET, &pEnumComp,
    if (hr==S_OK)
    hr = this->HrGetFirstComponent(pEnumComp, &pNetCfgComp);
    while (hr==S_OK)
    hr = pNetCfgComp->GetDisplayName(&displayName);

    if (wcscmp(displayName, adapterName)==0)

    hr = pNetCfgComp->QueryInterface( IID_INetCfgComponentBindings, (PVOID
    *)&pNetCfgCompBind );
    if ( hr == S_OK )
    // PATHS
    LPWSTR path;
    hr = this->HrGetBindingPathEnum(pNetCfgComp,EBP_BELOW,&pEnumBind);
    if (hr==S_OK)
    hr = this->HrGetFirstBindingPath(pEnumBind, &pNetCfgBind);
    while (hr==S_OK)
    hr = pNetCfgBind->GetPathToken(&path);
    hr = pNetCfgCompBind->MoveBefore(pNetCfgBind,NULL); // Move adapter
    binding to Primary
    hr = this->HrGetNextBindingPath(pEnumBind, &pNetCfgBind);

    hr = this->HrGetNextComponent(pEnumComp, &pNetCfgComp);
    return hr;
    Juan Morato, May 3, 2006
    1. Advertisements

  2. This has been asked in this NG some time ago, but apparently no
    solution was presented.

    Try and enable netcfg debug tracing as that might give you some hints,
    -> "Getting Trace from NETCFG.DLL"

    P.S.: Please post any results/solution that you find. Thanks!
    Stephan Wolf [MVP], May 3, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.