How to enable/disable network adapters?

G

Guest

Hello,

I need to enable/disable network adapters from my VB.NET code, e.g. enable
wlan, disable lan. I know the names of the adapters, so I've thought about
using an api call like the one that is used by the "Network connection
manager" (connmc.exe); there you can choose an adapter from a list, and
enable/disable it. But I haven't found this function, yet. Can anybody point
me into the right direction? Maybe I can "automate" this connmc.exe, meaning
start the exe from my code, select the specific adapter from the list
control, "click" the menu???
Btw, I read about binding, rebinding and unbinding an adapter? What does
this mean? Is it disabling the adapter or is it a kind of reset of the
adapter?

With kind regards,
Thorsten Kleinhenz
 
P

Paul G. Tobey [eMVP]

Enable and Disable in the Network and DialUp Connections manager is actually
setting a bit in the registry for the target adapter and then calling NDIS
to unbind or bind (depending on whether your disabling or enabling the
adapter). NDIS picks up the flag setting during this binding process. I
can't find my notes on the values of flag that represent 'enabled' and
'disabled', but you should be able to use the Remote Registry Editor to
export the registry with a given adapter enabled, then disabled, and a
comparison program to figure that out.

Paul T.
 
G

Guest

I am also trying to enable/disable network adapters. I have found the
registry key for enabling/disabling network adapter, which is:
[HKEY_LOCAL_MACHINE\Comm\NdisPower]
<adapterName>=dword:00000004 ; disabled (delete this value for enabled)

But i cannot figure out how to do a NDIS bind or NDIS unbind through VB.net.
The only API that i have found is:
VOID NdisMRebindProtocolsToAdapter(
NDIS_HANDLE MiniportAdapterHandle
);

But I do not know how to P/Invoke this function because of the NDIS_HANDLE
struct as it's argument. Any help on how to do an NDIS bind or NDIS unbind
through VB.net ?
 
P

Paul G. Tobey [eMVP]

Use OpenNETCF. The .Net namespace has Unbind, Rebind, and Bind methods for
doing this. Make sure that you get the latest source from the Vault,
however, as there was a recent bug fix.

Paul T.

Dante said:
I am also trying to enable/disable network adapters. I have found the
registry key for enabling/disabling network adapter, which is:
[HKEY_LOCAL_MACHINE\Comm\NdisPower]
<adapterName>=dword:00000004 ; disabled (delete this value for enabled)

But i cannot figure out how to do a NDIS bind or NDIS unbind through
VB.net.
The only API that i have found is:
VOID NdisMRebindProtocolsToAdapter(
NDIS_HANDLE MiniportAdapterHandle
);

But I do not know how to P/Invoke this function because of the NDIS_HANDLE
struct as it's argument. Any help on how to do an NDIS bind or NDIS unbind
through VB.net ?







Paul G. Tobey said:
Enable and Disable in the Network and DialUp Connections manager is
actually
setting a bit in the registry for the target adapter and then calling
NDIS
to unbind or bind (depending on whether your disabling or enabling the
adapter). NDIS picks up the flag setting during this binding process. I
can't find my notes on the values of flag that represent 'enabled' and
'disabled', but you should be able to use the Remote Registry Editor to
export the registry with a given adapter enabled, then disabled, and a
comparison program to figure that out.

Paul T.

in
message news:[email protected]...
 
G

Guest

Hello Paul, hello Dante,
thanks for the information.
Actually I can disable an adapter via setting the mentioned registry key and
unbind the adapter. This sets the adapter even in the ConnectionManager to
disabled. But when I delete the registry key and bind the adapter I need to
enable the adapter via ConnectionManager again... is there anything else I
have to do to enable it? Or could this be a bug in my WinCE.NET 4.2 image?
Another question, what does to bind/unbind "exactly" mean?

Regards,
Thorsten
 
P

Paul G. Tobey [eMVP]

I can't help you with Connection Manager (don't have a PPC, even).

Binding is loading the adapter and attaching it, virtually, to each protocol
stack that the registry wants it connected to. On the desktop, this might
make connections between the adapter, TCP/IP, IPX/SPX (if you are using
NetWare on your network), etc. On Windows CE, it basically just connects
the adapter to TCP/IP. When it's bound, the TCP/IP stack has to get an IP
address for it (by reading it from the registry, if it's a static address,
or by contacting a DHCP server, if that's the configuration), etc.

Paul T.
 
K

KAUSHIK BOSE

Plese tell me how will I enable a Loopback adapter of windows 2003 server
from windows registry(HKEY_LOCAL_MACHINE).Step by step.
Suppose I have a standalone machine.I have 2 drive(c: & d:)
c: drive contains windows XP d: drive contains windows 2003 server and
d:drive also contains exchange server2003.
I have a loop back adaptor. Suddenly I disabled the adapter and shut down
the machine.But now I cannot open windows 2003 server. Machine stops and
showing "setting network connections"
 
K

KAUSHIK BOSE

Plese tell me how will I enable a Loopback adapter of windows 2003 server
from windows registry(HKEY_LOCAL_MACHINE).Step by step.
Suppose I have a standalone machine.I have 2 drive(c: & d:)
c: drive contains windows XP d: drive contains windows 2003 server and
d:drive also contains exchange server2003.
I have a loop back adaptor. Suddenly I disabled the adapter and shut down
the machine.But now I cannot open windows 2003 server. Machine stops and
showing "setting network connections".My email address is
(e-mail address removed)
 
P

Paul G. Tobey [eMVP]

Let me point out that you've posted to the wrong group. This group is for
discussion of .NET Compact Framework programming on Windows CE and Windows
Mobile devices, not for Windows Server or XP. You'll get better answers
faster if you ask in a sensible group.

Paul T.
 
P

Paul G. Tobey [eMVP]

Check the archives...

If you want to disable the adapter just during the current session (until
the next reboot), you can unbind it from NDIS, after telling NDIS to unpower
the adapter. OpenNETCF's Smart Device Framework has suitable methods for
doing the unbind of an adapter. You'll probably have to unpower the adapter
yourself (although OpenNETCF does have the P/Invoke for SetDevicePower()).
The best reference to this is the actual connection manager code for Windows
CE, which, if you are the device vendor, you can find in
\PUBLIC\COMMON\OAK\DRIVERS\CONNMC.

If you want to permanently disable the adapter (have the adapter disable
after reboot), you have to set a flag in the registry entry for the adapter,
and unbind/unpower it (and save the registry, of course).

Paul T.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top