npocmaka Posted January 16, 2010 Posted January 16, 2010 Hi, Here is my first script on AutoIt.While there is no command line utility that can turn off/on protocols i've created autoit script that can do this with ipv4 protocol.Currently it works only with WinXP and Win Server 2003 : expandcollapse popupIf (@OSVersion <> "WIN_2003") And (@OSVersion <> "WIN_XP") And (@OSVersion <> "WIN_XPe") Then ConsoleWrite("Suported OS version are WinXP and Windows Server 2003 " & @CRLF) Exit 2 EndIf if ($CmdLine[0] <> 2 ) And ($CmdLine[2]<>"on" Or $CmdLine[2]<>"off") Then ConsoleWrite("expected parameters are : Loca Area Connection Name and on/off switch for ipv4 stack " & @CRLF) Exit 1 EndIf Dim $connectionName ;e.g. "Local Area Connecion" Dim $switcher $connectionName=$CmdLine[1] $switcher=$CmdLine[2] $networkProperties=$connectionName & " Properties" ;ConsoleWrite($networkProperties & @CRLF) $networkStatus=$connectionName & " Status" ;ConsoleWrite($networkStatus & @CRLF) WinClose($networkProperties) sleep(100) WinClose($networkStatus) sleep(100) WinClose("Network Connections") sleep(100) Run("explorer ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}") ;Run("control ncpa.cpl") sleep (1500) WinActivate ( "Network Connections") dim $loop_counter $loop_counter=0 While Not WinActive ( "Network Connections" ) $loop_counter+=1 sleep(10) if($loop_counter = 100 ) then ConsoleWrite("Cannot handle Network Connections window " & @CRLF) exit 3 EndIf WEnd ;$active_win=WinActive ( "Network Connections" ) ;ConsoleWrite("active= " & $active_win & @CRLF) $selected_class = ControlGetFocus("[CLASS:CabinetWClass]") ;ConsoleWrite("selected= " & $selected_class & @CRLF) ControlFocus ( "[Class:SysListView32]", "", "SysListView321") $b=ControlListView("Network Connections" ,"", "SysListView321","FindItem", $connectionName) $c=ControlListView("Network Connections" ,"", "SysListView321","GetText", 1) ;ConsoleWrite("selected= " & $b & @CRLF) ;ConsoleWrite("info= " & $c & @CRLF) ControlListView("Network Connections" ,"", "SysListView321","Select", $b) Send("{ENTER}") sleep (2000) Send("!p") sleep (2000) WinActivate ($networkProperties) $loop_counter=0 While Not WinActivate ($networkProperties) $loop_counter+=1 sleep(10) if($loop_counter = 100 ) then ConsoleWrite("Cannot handle Network Properties window " & @CRLF) exit 4 EndIf WEnd $selected_class2 = ControlGetFocus($networkProperties) $items_count=ControlListView($networkProperties ,"", "SysListView321","GetItemCount") ;ConsoleWrite("count= " & $items_count & @CRLF) $item_text="" $ipv4_pos=-1 For $i=0 to $items_count-1 Step 1 $item_text=ControlListView($networkProperties ,"", "SysListView321","GetText", $i) ;Internet Protocol Version 6 (TCP/IPv6) $compare=StringCompare ( "Internet Protocol (TCP/IP)", $item_text ) ;ipv4 protocol is always installed on XP and Server 2003 if $compare = 0 then $ipv4_pos=$i ExitLoop EndIf Next if $ipv4_pos=-1 Then ConsoleWrite("Cannot find ip4 protocol " & @CRLF) Exit 5 EndIf Send("{PGUP}") sleep(100) for $i=1 to $ipv4_pos step 1 sleep(100) Send("{DOWN}") Next sleep (10) ;ConsoleWrite("ipv4 position= " & $ipv4_pos & @CRLF) $is_en=ControlCommand($networkProperties, "", "Button4", "IsEnabled", "") ;When tcp/ip is enabled "properties" button is active and I'm using this a check ;Not works with Vista,Windows 7 and Windows Server 2008 ;ConsoleWrite("cch4= " & $is_ch & @CRLF) If $switcher="off" and $is_en=1 Then Send("{SPACE}") EndIf If $switcher="on" and $is_en=0 Then Send("{SPACE}") EndIf ControlClick ( $networkProperties, "", "Button8") sleep (2000) WinClose($networkStatus) sleep(100) WinClose("Network Connections") sleep(100) Currently I'm trying to make Vista and Windows 7 version.The problem is that I've no idea how to check if tcp/ip protocol is enabled on newer versions of Windows.On XP I'm just checking if properties button is active but when I open any Local Connection with autoit properties button is always inactive.Anyway I hope this will be usefull for somebody
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now