I've looked into automagically enable/disable network connections before. Heres what I came up with.

First I aimed for the registry, it seems like disable a connection clears the NTEContextList of the interface and reduces a reference count (Yes!) to the interface. Enable it sets a unique hex counter on NTEContextList and increases the reference count. It probably does more that that, so I decided not to fiddle with it.

I decided to go for a solution using the Win32::GuiTest module and emulate a user (Me) doing it.

Here is my code, you'll probably need to modify it to match your icon positions and maybe increase/decrease the sleep values.
#!/usr/bin/perl -w use strict; use Win32::GuiTest qw(SetForegroundWindow FindWindowLike GetWindowText + SendKeys); use vars qw(@windows); #- Check for open ncpa.cpl @windows = FindWindowLike(0, "Network and Dial-up Connections", "", 0, + 1); #- Close all open ones for (@windows) { SetForegroundWindow($_); sleep 1; SendKeys("%{F4}"); } #- Open a new one system ("cmd /c start ncpa.cpl"); sleep 2; @windows = FindWindowLike(0, "Network and Dial-up Connections", "", 0, + 1); SetForegroundWindow($windows[0]); sleep 1; #- Now, navigate to the icon you want with right arrow keys #- Mine is the second icon so I need only one keystroke SendKeys("{RIGHT}"); #- Open the right klick menu and press enable/disable SendKeys("+{F10}{DOWN}~"); #- Wait a while (enabling takes some time) sleep 15; #- Close window SendKeys("%{F4}");
Good luck,

/brother t0mas

In reply to Re: w2k networking by t0mas
in thread w2k networking by jdv79

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.