Sign in to follow this  
Followers 0
rjdegraff

WinActivate doesn't

5 posts in this topic

I have two apps that have to start automatically when the machine starts up (actually two instances of the same app with different parameters). I have a CMD file that runs the startup code in sequence.

StartVista.cmd

-----------------

cd "d:\vista\server import"

cscript StartServer.vbs

cd "d:\vista\server process"

cscript StartServer.vbs

The two vbScripts are identical except for the value of the variable "server". The first server instance always starts as expected, however, when the second instance starts up, the "Connection Dialog" window never gets activated. The window is displayed but it never gets focus. With the "Active Window Tool" running, even if I manually select the window, it still doesn't register as having focus.

StartServer.vbs

------------------

server = "Import Vista Data"

set wso = CreateObject("Wscript.Shell")

set aut = CreateObject("AutoitX3.Control")

wso.Run "..\exe\svr_app.exe",1,false

title = "Connection Dialog"

aut.Opt "WinTitleMatchMode",2

aut.WinWait title

aut.WinActivate title

aut.WinWaitActive title

aut.ControlSetText title,"","4207","svr_app_admin"

aut.ControlSetText title,"","4215","svr_app_admin"

aut.ControlClick title,"OK","1"

title = "Server Settings"

aut.WinWait title

aut.WinActivate title

aut.WinWaitActive title

aut.ControlClick title,"Manual","128"

aut.Sleep 1000

aut.ControlClick title,"OK","1"

aut.Sleep 2000

SetTitle "Operational Data Processor - Server - [status]",Server

Function SetTitle ( currtitle , newtitle )

on error resume next

wso.Run "cmdow.exe " & """" & currTitle & """" & " /REN """ & newtitle & """", 0, True

if err.Number <> 0 then err.Clear

End Function

Share this post


Link to post
Share on other sites



Looks like you are using Control* functions. You should be able to forget about the concern for active windows. Use WinWait and Control* functions to process the windows. WinWaitActive and WinActivate should not be required.

Note: AutoIt can work with inactive windows with the Control* functions.

Share this post


Link to post
Share on other sites

Looks like you are using Control* functions. You should be able to forget about the concern for active windows. Use WinWait and Control* functions to process the windows. WinWaitActive and WinActivate should not be required.

Note: AutoIt can work with inactive windows with the Control* functions.

<{POST_SNAPBACK}>

Makes no difference. I commented out those lines and got the same results. What would happen, say, if the settings window from the first running of svr_app.exe was not destroyed by the application, just made invisible (or hidden)? It would still have the same window title as the second instance (wouldn't it) and perhaps the commands are going to the hidden window instead of the visible one. This is pure speculation but it might explain the behavior.

Share this post


Link to post
Share on other sites

I reviewed your script. Your ControlClick functions have the optional button parameter used, but have the incorrect type of information. I do not believe that CMDOW is needed, as AutoItX can change titles. Removed the WinWaitActive and WinActivate functions. Changed the CreateObject functions to correct syntax.

No experience with AutoItX, so do not take this for granted, but as a different view.

server = "Import Vista Data"

set wso = WScript.CreateObject("Wscript.Shell")
set aut = WScript.CreateObject("AutoitX3.Control")

aut.Opt "WinTitleMatchMode",2

wso.Run "..\exe\svr_app.exe",1,false

title = "Connection Dialog"

aut.WinWait title
aut.ControlSetText title,"","4207","svr_app_admin"
aut.ControlSetText title,"","4215","svr_app_admin"
aut.ControlClick title,"OK","left"

title = "Server Settings"

aut.WinWait title
aut.ControlClick title,"Manual","left"
aut.Sleep 1000
aut.ControlClick title,"OK","left"
aut.Sleep 2000

title = "Operational Data Processor - Server - [Status]"

aut.WinWait title
aut.WinSetTitle "Operational Data Processor - Server - [Status]",Server

set wso = Nothing
set aut = Nothing

Share this post


Link to post
Share on other sites

Your help was useful and very much appreciated. I used the WinSetTitle to change the names of the logion and server settings windows to names specific to each process and the mouse clicks, etc went where they were supposed to. It's working just fine now.

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