Jump to content
Sign in to follow this  
dhhcdad

OK button on Excel 2010 password box

Recommended Posts

dhhcdad

Under Win7 64-bit, in Excel 2010, the OK button (or the CANCEL button, for that matter) on the Password box does now show any control information when checked via Au3Info_x64.exe. Can see the control info for the password box, though.

Anyone know why?

More importantly, in the absence of control information, how to automate the clicking of the OK button?

Much appreciate your help.

Share this post


Link to post
Share on other sites
jdelaney

Without seeing the window/info, I would suggest using WinGetClassList(), and then use some logic to get the handles of all the controls (some identifiers to, like the control text)

Sometimes the window info tool only get's the parent object, and can't focus on the children. The above will work around this.

example

#include <Array.au3>
$hWin = "YOUR HANDLE OR TITLE"
$sClassList = WinGetClassList($hWin)
$aClassList = StringSplit($sClassList,@CRLF,2)
_ArraySort ($aClassList)
_ArrayDelete ($aClassList, 0 )
Dim $aClassAndHandle[UBound($aClassList)][3]
$sPreviousClass = ""
$iCounter = 0
For $i = 0 To UBound ($aClassList) - 1
If $aClassList[$i]<>$sPreviousClass Then
$iCounter = 1
$sPreviousClass = $aClassList[$i]
Else
$iCounter += 1
EndIf
$aClassAndHandle[$i][0] = ControlGetHandle ($hWin, "", $aClassList[$i] & $iCounter)
$aClassAndHandle[$i][1] = ControlGetText ($hWin, "", $aClassAndHandle[$i][0])
$aClassAndHandle[$i][2] = $aClassList[$i]
Next
_ArrayDisplay ($aClassAndHandle)

Another solution, since buttons are easier to get information of by text, is to use the buttons text.:

ControlGetHandle ($hwnin,"","[CLASS:Button; TEXT:TEXTOFBUTTON]")

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

What do you want to do with Excel (open a password protected worksheet ...) so that you get the password box?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
dhhcdad

Hi water. Thanks for the welcome. Thanks for supporting the forum. This is my first post, but I've read and learned a lot from this forum.

The goal is simply to supply the password and click on the OK button--so that the password box can be suppressed.

Abode Acrobat Reader also puts up a simple password box (seemingly identical to the password box that Excel 2010 uses), and Au3Info_x64.exe has no problem picking up the control info for the OK button there. Something must be different with Excel 2010.

Share this post


Link to post
Share on other sites
dhhcdad

jdelaney, thanks. Will try your suggestions and report back.

Share this post


Link to post
Share on other sites
water

Yeah, but when does the password box pop up? When you try to open the Excel workbook?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Cybergraph

Why you don't use the _ExcelBookOpen function, where you can easily insert the password as a parameter without messing with buttons and controls?

Share this post


Link to post
Share on other sites
water

Exactly!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
dhhcdad

Why you don't use the _ExcelBookOpen function, where you can easily insert the password as a parameter without messing with buttons and controls?

Well, the trouble is that the script is not in position to initiate the opening of the workbook, nor does it have the path and name of the workbook at hand.

Share this post


Link to post
Share on other sites
water

And who is going to enter the password? The user who opened the workbook or your script?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
dhhcdad

And who is going to enter the password? The user who opened the workbook or your script?

The script would enter the password and click OK to dismiss the password dialog box.

Share this post


Link to post
Share on other sites
water

But why do you then set a password at all?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
dhhcdad

But why do you then set a password at all?

That's just how it is.

Share this post


Link to post
Share on other sites
dhhcdad

Without seeing the window/info, I would suggest using WinGetClassList(), and then use some logic to get the handles of all the controls (some identifiers to, like the control text)

Sometimes the window info tool only get's the parent object, and can't focus on the children. The above will work around this.

example

#include <Array.au3>
$hWin = "YOUR HANDLE OR TITLE"
$sClassList = WinGetClassList($hWin)
$aClassList = StringSplit($sClassList,@CRLF,2)
_ArraySort ($aClassList)
_ArrayDelete ($aClassList, 0 )
Dim $aClassAndHandle[UBound($aClassList)][3]
$sPreviousClass = ""
$iCounter = 0
For $i = 0 To UBound ($aClassList) - 1
If $aClassList[$i]<>$sPreviousClass Then
$iCounter = 1
$sPreviousClass = $aClassList[$i]
Else
$iCounter += 1
EndIf
$aClassAndHandle[$i][0] = ControlGetHandle ($hWin, "", $aClassList[$i] & $iCounter)
$aClassAndHandle[$i][1] = ControlGetText ($hWin, "", $aClassAndHandle[$i][0])
$aClassAndHandle[$i][2] = $aClassList[$i]
Next
_ArrayDisplay ($aClassAndHandle)

Another solution, since buttons are easier to get information of by text, is to use the buttons text.:

ControlGetHandle ($hwnin,"","[CLASS:Button; TEXT:TEXTOFBUTTON]")

I took your code and made slight modifications, as follows, and ran it:

#include <Array.au3>
$hWin = "Password"

while 1

winwaitactive($hWin)
$sClassList = WinGetClassList($hWin)
$aClassList = StringSplit($sClassList,@CRLF,2)
_ArraySort ($aClassList)
_ArrayDelete ($aClassList, 0 )
Dim $aClassAndHandle[UBound($aClassList)][3]
$sPreviousClass = ""
$iCounter = 0
For $i = 0 To UBound ($aClassList) - 1
If $aClassList[$i]<>$sPreviousClass Then
$iCounter = 1
$sPreviousClass = $aClassList[$i]
Else
$iCounter += 1
EndIf
$aClassAndHandle[$i][0] = ControlGetHandle ($hWin, "", $aClassList[$i] & $iCounter)
$aClassAndHandle[$i][1] = ControlGetText ($hWin, "", $aClassAndHandle[$i][0])
$aClassAndHandle[$i][2] = $aClassList[$i]
Next
_ArrayDisplay ($aClassAndHandle)


wend

The result, for the Excel 2010 Password dialog box, is that the array output only shows one row that represents the EDITBX.

For comparsion, I ran the same test for an Adobe Acrobat Password dialog box, and the array output showed six rows which included both the OK and Cancel buttons as well as the static text items, etc.

Haven't tried your second suggstion yet. Will report back after. Thanks.

Share this post


Link to post
Share on other sites
dhhcdad

Tried the ControlGetHandle method as follows:

Local $hHandle = ControlGetHandle ($hWin,"","[CLASS:Button; TEXT:OK]")
MsgBox(0, "ControlGetHandle Example", "The control handle of Button is: " & $hHandle)
 
Local $hHandle = ControlGetHandle ($hWin,"","[CLASS:Button; INSTANCE:1]")
MsgBox(0, "ControlGetHandle Example", "The control handle of Button is: " & $hHandle)

Neither managed to return the handle. It is as if the OK and CANCEL buttons do not exist on that window.

Share this post


Link to post
Share on other sites
Bowmore

This works for me although I would personally use the Excel COM interface.

Example:

prerequisite is that the password input dialog is visible

Unlock("yourpassword")

Func Unlock($Password)
$hwnd = WinActivate("Unprotect Sheet","")
ControlFocus($hwnd,"","[CLASS:EDTBX]")
ControlSetText($hwnd,"","[CLASS:EDTBX;]",$Password)
ControlSend($hwnd,"","[CLASS:EDTBX]","{TAB 1}{ENTER}")
;~ ControlSend($hwnd,"","[CLASS:EDTBX]","{TAB 2}{ENTER}") ;<==== Click cancel if require
EndFunc

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites
dhhcdad

This works for me although I would personally use the Excel COM interface.

Example:

prerequisite is that the password input dialog is visible

Unlock("yourpassword")

Func Unlock($Password)
$hwnd = WinActivate("Unprotect Sheet","")
ControlFocus($hwnd,"","[CLASS:EDTBX]")
ControlSetText($hwnd,"","[CLASS:EDTBX;]",$Password)
ControlSend($hwnd,"","[CLASS:EDTBX]","{TAB 1}{ENTER}")
;~ ControlSend($hwnd,"","[CLASS:EDTBX]","{TAB 2}{ENTER}") ;<==== Click cancel if require
EndFunc

This method worked for me also. Thanks!

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  

×