Sign in to follow this  
Followers 0
kstokking

Problems with Window and Control Focusing

2 posts in this topic

I am trying to automate a 3rd party program to automatically log in and kick off an import feature. Ideally, I would like the process to be kicked off from a Web Service or possibly a Windows Service, but I am running into some problems. First off, here is the code:

$logPath = "C:\temp\ImportLog.txt"
$exe = "D:\Some Path\Some.exe"

$username = "username"
$password = "password" ;;;;Wouldn't you like to know....
$server = "server"
$db = "db"

$begin = TimerInit()
$logfile = FileOpen($logPath, 1)
If $logfile = -1 Then
   Exit
EndIf

;RunAsSet("administrator", "SERVER", "password");
Run($exe)
sleep(2000)

FileWriteLine($logfile, "Login")
FileWriteLine($logfile, "Exists?: " & WinExists("Welcome"))
FileWriteLine($logfile, "Activate?: " & WinActivate("Welcome"))
FileWriteLine($logfile, "Focus of Welcome: " & ControlGetFocus("Welcome"))

$state = WinGetState("Welcome")
FileWriteLine($logfile, "Window exists: " & BitAnd($state, 1))
FileWriteLine($logfile, "Window is visible: " & BitAnd($state, 2))
FileWriteLine($logfile, "Window is enabled: " & BitAnd($state, 4))
FileWriteLine($logfile, "Window is active: " & BitAnd($state, 8))
FileWriteLine($logfile, "Window is minimized: " & BitAnd($state, 16))
FileWriteLine($logfile, "Window is maximized: " & BitAnd($state, 32))
FileWriteLine($logfile, "Focus Control work?: " & ControlFocus("Welcome", "", "[CLASSNN:Edit7]"))
FileWriteLine($logfile, "Focused Control: " & ControlGetFocus("Welcome" ))

WinClose("Welcome")
FileClose($logfile)
Exit

If I run this when I'm connected to the machine, either through the console or remote desktop, I get the following results:

Exists?: 1

Activate?: 1

Focus of Welcome: Edit8

Window exists: 1

Window is visible: 2

Window is enabled: 4

Window is active: 8

Window is minimized: 0

Window is maximized: 0

Focus Control work?: 1

Focused Control: Edit8

What I can infer from this is that a window titled "Welcome" pops up, is visible, is enabled, and automatically becomes active. As far as I can tell on my screen, these are all true. However, when I try to focus control Edit7, it does not work (even though it returns 1). The focus stays at Edit7. Odd.

When I run the Au3 executable from a Windows Service (running under the same user), I get the following results:

Exists?: 1

Activate?: 1

Focus of Welcome: pbdw902 ;;;;;I don't know what this means, but as far as I can tell it's just garbage

Window exists: 1

Window is visible: 0

Window is enabled: 4

Window is active: 0

Window is minimized: 0

Window is maximized: 0

Focus Control work?: 1

Focused Control: Edit7

What I can infer from this is that a window titled "Welcome" exists and is enabled, but it is not enabled and not active even though I told it to activate and that function returned 1. I assume that the window did not activate because it's not visible - is there a way around this? What is also very strange is that the Focused Control for this DID change to Edit7 when I told it to, even though it didn't in the previous example...

I guess my basic questions are this, is it possible to Activate a window if it's not visible, or is there some other workaround for it? Also, how come the focus of the control does not change even though the function returns 1 and, as far as I could tell, there was no reason not to? This becomes an issue when I try to use ControlSetText - it does not actually set any text, I believe because it does not actually Focus on the control.

All of this is done on a Windows 2003 R2 SP2 machine. The Windows Service was written in .Net 2.0. I have AutoIT3 (downloaded 2 weeks ago).

Thanks in advance for any help.

Share this post


Link to post
Share on other sites



Im not sure what you want to do here can you try to explain it some more are you trying to log into a program and log all the logins/passwords


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