Hello everyone,
I have been trying to find a way to activate/inactivate network cards in .NET, kinda like ifconfig up and ifconfig down on Linux. The reason is that I simply don't want Windows to automatically choose one interface over the other and use this, but to decide for myself.
Is there any good way to do this in .NET I found that IP Helper API can list all interfaces, but it does not seem to be able to manage them. Thanks a lot for any tips!
/ Roland

selecting network interfaces
Gaturam
Well, a friend told me how to do this. If anyone else wonders, simply use
socket.bind(EndPoint)
(how could I miss it )
Thanks again all.
FigBug
HRESULT DisableEnableConnections(BOOL bEnable)
{
HRESULT hr = E_FAIL;
CoInitialize(NULL);
INetConnectionManager *pNetConnectionManager = NULL;
hr = CoCreateInstance(CLSID_ConnectionManager,
NULL,
CLSCTX_LOCAL_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
IID_INetConnectionManager,
reinterpret_cast<LPVOID *>(&pNetConnectionManager));
if (SUCCEEDED(hr)){
// Get an enumurator for the set of connections on the systemIEnumNetConnection* pEnumNetConnection;
pNetConnectionManager->EnumConnections(NCME_DEFAULT, &pEnumNetConnection);
ULONG ulCount = 0;
BOOL fFound = FALSE;
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
HRESULT hrT = S_OK;
// Enumurate through the list of adapters on the system and look for the one we want // NOTE: To include per-user RAS connections in the list, you need to set the COM // Proxy Blanket on all the interfaces. This is not needed for All-user RAS // connections or LAN connections. do{
NETCON_PROPERTIES* pProps = NULL;
INetConnection * pConn;
// Find the next (or first connection)hrT = pEnumNetConnection->Next(1, &pConn, &ulCount);
if (SUCCEEDED(hrT) && 1 == ulCount){
hrT = pConn->GetProperties(&pProps);
// Get the connection properties if (S_OK == hrT){
printf(
"* %S\n", pProps->pszwName); if (bEnable){
printf(
" Enabling adapter: %S...\n",pProps->pszwName);hr = pConn->Connect();
}
else{
printf(
" Disabling adapter: %S...\n",pProps->pszwName);hr = pConn->Disconnect();
}
CoTaskMemFree (pProps->pszwName);
CoTaskMemFree (pProps->pszwDeviceName);
CoTaskMemFree (pProps);
}
pConn->Release();
pConn = NULL;
}
}
while (SUCCEEDED(hrT) && 1 == ulCount && !fFound); if (FAILED(hrT)){
hr = hrT;
}
pEnumNetConnection->Release();
}
if (FAILED(hr) && hr != HRESULT_FROM_WIN32(ERROR_RETRY)){
printf(
"Could not enable or disable connection (0x%08x)\r\n", hr);}
pNetConnectionManager->Release();
CoUninitialize();
return hr;}
Jelle van der Beek30865
BlkShdw88
Steve_Black
adelgado
Parrot
http://msdn.microsoft.com/library/default.asp url=/library/en-us/wmisdk/wmi/wmi_tasks__networking.asp
http://www.codeproject.com/csharp/wmimadeeasy.asp
(I pulled this information from http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=114198&SiteID=1)
Anthony Kautz
[
excerpt from http://www.robvanderwoude.com/index.html
DEVCON is a Microsoft tool that allows "device management" from the command line.
It is available for free at http://support.microsoft.com/default.aspx scid=kb;EN-US;Q311272.
]
allows you to do this.
Also see
http://www.novell.com/coolsolutions/tools/14784.html