+ Post New Thread
Results 1 to 7 of 7
Coding Thread, Programmatically enable/disable a network interface? in Coding and Web Development; I am trying to write in a 'self fixer' to a program to fix an issue with wireless connectivity over ...
  1. #1

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,096
    Thank Post
    511
    Thanked 2,310 Times in 1,786 Posts
    Blog Entries
    24
    Rep Power
    803

    Programmatically enable/disable a network interface?

    I am trying to write in a 'self fixer' to a program to fix an issue with wireless connectivity over a long time.

    Namely, it seems that over time, wireless connections always seem to drop. The fix always being disabling and re-enabling the connection. As I know what this fix is, how can I write it into the software to do it itself should it need to?

    My idea was this:

    Normal activity of the program fails for whatever reason. In the try/catch block, it would check to see if the device was active, if it wasn't, enable it, run a ping and based on the result of that, try again.

    However, every reference to doing this I come across is like running into a big Microsoft shaped wall.

    Does anybody have any ideas as to API calls within Windows XP which I can use to do a simple enable/disable of a named connection? It seems that you can do it in Vista, but the devices I'm working with are embedded systems and therefore, no Vista (not to mention they only have 256Mb RAM).

  2. #2

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,374
    Thank Post
    625
    Thanked 951 Times in 653 Posts
    Blog Entries
    2
    Rep Power
    318
    Does disabling and re-enabling the device from the Device Manager do the same thing? If so, devcon could be the answer: Enable/disable a device from the command line - The solution

  3. Thanks to webman from:

    localzuk (29th January 2010)

  4. #3

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    10,691
    Thank Post
    824
    Thanked 2,570 Times in 2,187 Posts
    Blog Entries
    9
    Rep Power
    731

  5. Thanks to SYNACK from:

    localzuk (29th January 2010)

  6. #4

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,096
    Thank Post
    511
    Thanked 2,310 Times in 1,786 Posts
    Blog Entries
    24
    Rep Power
    803
    Quote Originally Posted by webman View Post
    Does disabling and re-enabling the device from the Device Manager do the same thing? If so, devcon could be the answer: Enable/disable a device from the command line - The solution
    It would be ideal, however, from Microsoft 'DevCon is not redistributable. It is provided for use as a debugging and development tool.'

    Looks interesting. I'll take a peak.

  7. #5

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,374
    Thank Post
    625
    Thanked 951 Times in 653 Posts
    Blog Entries
    2
    Rep Power
    318
    Ah - curses!

    If you can do an AutoIt script, there's some posts in the forum which might work:

    Disable/Enable Local Area Connection - AutoIt Forums

  8. #6

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,096
    Thank Post
    511
    Thanked 2,310 Times in 1,786 Posts
    Blog Entries
    24
    Rep Power
    803
    The Native WIFI API has led me to this Managed Wifi API

    Which looks like it'll be perfect, should it work

  9. #7

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,096
    Thank Post
    511
    Thanked 2,310 Times in 1,786 Posts
    Blog Entries
    24
    Rep Power
    803
    Just an update for anyone else who is interested.

    I have now achieved my goal by doing the following:

    1. The test method runs a ping
    2. If the ping succeeds, then the connectivity returns as OK
    3. If not, the software looks for a predefined wireless LAN, and joins it (this automatically drops any other wireless LAN's you may be joined to.
    4. Waits a while (this is currently done via a crude thread.sleep() call but I will hopefully add a while loop with a WMI call to check it is connected.
    5. Pings again.
    6. If OK, continues running the program.
    7. If fails, then it informs the user and exits.

    This is done via the ManagedWifi API I mention in my earlier post, and the Ping method in c#

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 2
    Last Post: 7th February 2012, 06:46 PM
  2. Enable/Disable workstation internet access from shortcut
    By the_mighty_boosh in forum Netware
    Replies: 3
    Last Post: 28th January 2011, 09:34 AM
  3. Enable/Disable Proxy Settings (Easy Way)
    By Michael in forum Windows
    Replies: 33
    Last Post: 2nd July 2008, 10:47 AM
  4. Nagios plugin enable/disable interface
    By plexer in forum Wireless Networks
    Replies: 1
    Last Post: 4th March 2008, 01:54 PM
  5. Replies: 3
    Last Post: 7th February 2006, 01:51 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •