Reputation: 1117
I have a Nokaia 3G USB modem (stick) that I want to turn on and off programmatically.
This modem installs itself in Windows 7 as just another network adapter - no new modems are added.
Because no modem is added I cannot use RAS to establish connection from code, as I can (and do) with many other 3G USB modem sticks.
In the Network Connections window the network adapter looks like a WLAN adapter (you know, with those "signal strength bars" in the icon), and by right-clicking it i am able to do the connect/disconnect action interactively.
But how can I establsh connection from code with this modem? I'm sure there must be a simple way...?
Upvotes: 2
Views: 1625
Reputation: 131483
What you are really asking is, how to enable or disable a network connection. You can do this using WMI as shown in this SO question, to enable or disable the card, using the appropriate methods of the Win32_NetworkAdapter class. You can check, but not change, the connection status by reading the NetConnectionStatus property.
In your case you should probably use a query like:
"SELECT * FROM Win32_NetworkAdapter WHERE Manufacturer == 'Nokaia' "
or whatever the actual manufacturer name is. Querying by name is not guaranteed to work, as the user can change the name of the connection.
Also check "How can I tell if a wireless network is connected" on Technet for a more thorough description of how to use Win32_NetworkAdapter.
Upvotes: 1