Jump to content

Works the first time, but not the second?!


Recommended Posts

Hi guys,

I've been battling with this for a couple of days now and it's driving me crazy.  I'm very new to AutoIT but I logically cannot work out why this doesn't work.

I'm trying to to change the link speed of a network adapter in Windows 7 Pro 64bit, from 100Mb/Full, to auto negotiate.  I've already completed this exact script in XP and it works perfectly.  I expected to have to alter a few things to get it to work with Win7, but nothing like this.

It successfully opens up the Network Connections window, sends the text "local" to the window in order to highlight the Local Area Network adapter and then hits enter to open up it's status.  (This works fine)

It then clicks the Properties button at the bottom in order to open the properties window for the adapter. (This also works fine)

Here's were the trouble starts.  It is supposed to click the Configure button at the top of the properties window, but it just will not work.  The strange thing is, is that the Properties window is exactly the same class and window type as the Status window, so everything should be exactly the same to click this button, (apart from the being Button1, instead of Button2).

I just don't understand how it will work for the first window, but not the second.  Any help would be very much appreciated.

local $Net_Conn = "Network Connections"
local $LAN_Status = "Local Area Connection Status"
local $LAN_Props = "Local Area Connection Properties"

;**********************************************************************************

;launch Network Connections, then launch LAN_status and close Network Connections
;**********************************************************************************

Run("control ncpa.cpl")

WinWait( $Net_Conn)
If Not WinActive( $Net_Conn) Then
 WinActivate( $Net_Conn)
EndIf

ControlFocus( $Net_Conn, "", "DirectUIHWND3")
ControlSend( $Net_Conn, "", "DirectUIHWND3","local")
Send("{ENTER}")
;WinClose( $Net_Conn)

;**********************************************************************************
;wait till LAN_status window active, then click on Properties
;**********************************************************************************

WinWait($LAN_Status)
If Not WinActive($LAN_Status) Then
 WinActivate($LAN_Status)
EndIf

ControlFocus($LAN_Status, "", "[CLASS:Button; INSTANCE:2]")
ControlClick($LAN_Status, "", "[CLASS:Button; INSTANCE:2]")
;WinClose( $LAN_Status)

sleep(1000)

;Wait til LAN_Props window active, then click on Configure

WinWait($LAN_Props)
If Not WinActive($LAN_Props) Then
 WinActivate($LAN_Props)
EndIf


ControlFocus($LAN_Props, "", "[CLASS:Button; INSTANCE:1]")
ControlClick($LAN_Props, "", "[CLASS:Button; INSTANCE:1]")
sleep(500)

Thanks

Edited by MirageJ
Link to comment
Share on other sites

Rather than automating the Windows and Controls, why not interface with Windows directly? MSDN has an article for controlling network adapters here.

The examples are using wscript, but the COM stuff can easily be translated into AutoIt.

Local $oWMIService = ObjGet("winmgmts:\\"&"."&"\root\cimv2") ; Get the Windows Shell Object
Local $oColNetAdapters = $oWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where Index=7")
If IsObj($oColNetAdapters) Then
    For $oObjAdapter In $oColNetAdapters
        ConsoleWrite($oObjAdapter.NetConnectionID & " is set to " & $oObjAdapter.Speed & " speed" & @LF)
        ; To set the speed you might able to do this
        ; $oObjAdapter.Speed = 999999999 ; .1 slower
    Next
EndIf
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...