Change binding order of network adapters in Windows XP

Posted: 04-28-2006, 10:02 AM
Hello,
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 http://support.microsoft.com/kb/894564/en-us, and
what I do is
1 - acquire a write lock using
INetCfgLock->AcquireWriteLock
2 - enumerate all the components
INetCfgClass->EnumComponents
3 - search for the component I want to put on the top of the list.
4 - enumerate all the binding paths for the component
INetCfgComponentBindings->EnumBindingPaths
5 - for each binding path I try to call
INetCfgComponentBindings->MoveBefore
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
adapterName)
{
HRESULT hr= NULL;
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,
&pNetCfgClass);
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,&pEnum Bind);
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;
}

Reply With Quote

Responses to "Change binding order of network adapters in Windows XP"

 
LinkBack Thread Tools Display Modes
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change the binding order of network providers bulklodd Windows Vista Networking & Sharing 6 06-11-2008 08:51 PM
Changing binding order in Vista DJACK Windows Vista Networking & Sharing 1 04-04-2007 03:51 PM
VPN and binding order. indianabeck Windows Vista Networking & Sharing 0 01-08-2007 03:18 PM
Nic Binding Order Getty Lab Manager Windows Vista Networking & Sharing 0 10-06-2006 04:10 PM
Network Binding order and Protocols ganesh Windows XP WMI 0 09-13-2006 01:28 AM