in reply to w2k networking

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

Replies are listed 'Best First'.
Re: Re: w2k networking
by Anonymous Monk on Sep 19, 2002 at 18:04 UTC
    I appreciate the help! Its defintiely not a pure method(thats not anybodies fault but m$'s IMHO) but it will probably get the job done. Funky way of having to go about what is such a simple task in a *nix evironment. On one hand I am surprised and on the other I expected it to be like this-it almost always is with windows:) -Justin