#!/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}");