Sign in to follow this  
Followers 0
rlee

WinActivate fails when use not viewing desktop

2 posts in this topic

I have an automated build process that creates an executable which is signed via signcode. I have an autoit script that automatically fills in the password on the window that is popped up when signcode runs.

Here the process that happens.

1. Create output executable

2. Run signcode to sign the execuable. A window is displayed for entering the password.

3. Run autoit script to find the password from (2). This will time out after 30 sec if it couldn't fill in the password.

Everything runs fine when a user is logged in and viewing the desktop. However, I have set the script to run automatically via scheduled tasks and the autoit script never appears to find the window from (2). If I log in after a the sequence completes, the window from (2) is still present. If I run the script again, the password is filled in and everything continues on.

Here is my autoit script.

#Include <Timers.au3>

; Wait for password window and then enter the password
Opt("WinTitleMatchMode", 3) ;exact match

if $CmdLine[0] <> 1 Then
    ConsoleWrite("Usage: EnterPrivateKeyPassword.exe <password>")
    Exit(1)
EndIf

; Wait for main window and then open login dialog
Local $starttime = _Timer_Init()
While _Timer_Diff($starttime) < 30000 ; 30 sec
    WinActivate("Enter Private Key Password")
    if WinActive("Enter Private Key Password") Then
        ControlSetText("Enter Private Key Password","",501,$CmdLine[1])
        ControlClick("Enter Private Key Password","",1,"left")
        Exit(0);
    EndIf
    Sleep(1000) ; wait 1 sec before trying to active main window again
WEnd

ConsoleWrite("Failed to find private key window")
Exit(1)

Share this post


Link to post
Share on other sites



Welcome,

ControlSetText() and ControlClick() should work with out needing to have an active window so I would comment the WinActivate() and If WinActive() lines. Not logged in on the desktop usually means windows cannot be seen by you or activated. You may also need to enable a desktop interaction setting with scheduled tasks as it normally will not allow it by default IIRC.

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  
Followers 0