Jump to content
Sign in to follow this  

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)

ControlFocus( $Net_Conn, "", "DirectUIHWND3")
ControlSend( $Net_Conn, "", "DirectUIHWND3","local")
;WinClose( $Net_Conn)

;wait till LAN_status window active, then click on Properties

If Not WinActive($LAN_Status) Then

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


;Wait til LAN_Props window active, then click on Configure

If Not WinActive($LAN_Props) Then

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


Edited by MirageJ

Share this post

Link to post
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

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...