neo van matix Posted June 22, 2006 Posted June 22, 2006 Heyho,.. i write a little script for some installations for friends. Now, if someone opens a new window or an other program, the installation stops. I tried to write a function, like that: Func win($TITLE, $TEXT) IF WinExists($TITLE, $TEXT) Then IF NOT WinActive($TITLE, $TEXT) Then WinActivate($TITLE, $TEXT) EndIf EndIf EndFunc If the window is aktiv, nothing should happens. If it Exists, but is hidden by another application, it should be activated. I wrote these script to test the function: Func win($TITLE, $TEXT) IF WinExists($TITLE, $TEXT) Then IF NOT WinActive($TITLE, $TEXT) Then WinActivate($TITLE, $TEXT) EndIf EndIf EndFunc run("notepad.exe", "", @SW_DISABLE) ; tried with @SW_HIDE too $TITLE = "Unbenannt- Editor" $TEXT = "" win($TITLE, $TEXT) IF WinActive($TITLE, $TEXT) Then msgbox(0, "active!", "notepad active!") EndIf But nothing happens, if i start the au3 :/ Attention! English noob ^^
PsaltyDS Posted June 22, 2006 Posted June 22, 2006 Heyho,.. i write a little script for some installations for friends. Now, if someone opens a new window or an other program, the installation stops. I tried to write a function, like that: Func win($TITLE, $TEXT) IF WinExists($TITLE, $TEXT) Then IF NOT WinActive($TITLE, $TEXT) Then WinActivate($TITLE, $TEXT) EndIf EndIf EndFunc If the window is aktiv, nothing should happens. If it Exists, but is hidden by another application, it should be activated. I wrote these script to test the function: Func win($TITLE, $TEXT) IF WinExists($TITLE, $TEXT) Then IF NOT WinActive($TITLE, $TEXT) Then WinActivate($TITLE, $TEXT) EndIf EndIf EndFunc run("notepad.exe", "", @SW_DISABLE) ; tried with @SW_HIDE too $TITLE = "Unbenannt- Editor" $TEXT = "" win($TITLE, $TEXT) IF WinActive($TITLE, $TEXT) Then msgbox(0, "active!", "notepad active!") EndIf But nothing happens, if i start the au3 :/ You'd be better off with WinGetState() and WinSetState(). Disabled and hidden are not the same as not active. Get the state then conditionally deal with it. You script would probably work if you changed the initial state to @SW_MINIMIZED. But you'll need WinSetState() if you really want to deal with disabled/hidden windows. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
marfdaman Posted June 22, 2006 Posted June 22, 2006 Why not something like this: Func win($TITLE, $TEXT) IF WinExists($TITLE, $TEXT) Then IF NOT WinActive($TITLE, $TEXT) Then WinActivate($TITLE, $TEXT) EndIf EndIf EndFunc run("notepad.exe", "", @SW_MINIMIZE) ; tried with @SW_HIDE too $TITLE = "Untitled" $TEXT = "" win($TITLE, $TEXT) WinWaitActive($TITLE, $TEXT) msgbox(0, "active!", "notepad active!") Alzo Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
neo van matix Posted June 22, 2006 Author Posted June 22, 2006 Okay, i tried to use WinSetState, but i'm not sure, witch macro i should use... I tried to SW_HIDE and SW_SHOW, but... works not as fine as it should.. Then, i tried to SW_MINIMIZE the window. That works,... now i tried to activate the minimized window with SW_MAXIMIZE. The Window maximized to the Foreground, but was not active ?! can u give me a little example? :/ Attention! English noob ^^
marfdaman Posted June 22, 2006 Posted June 22, 2006 Okay, i tried to use WinSetState, but i'm not sure, witch macro i should use...I tried to SW_HIDE and SW_SHOW, but... works not as fine as it should..Then, i tried to SW_MINIMIZE the window. That works,... now i tried to activate the minimized window with SW_MAXIMIZE. The Window maximized to the Foreground, but was not active ?!can u give me a little example? :/Could you describe exactly what happens/should happen, step by step, when you run the installation pleaz...That way we could help you better. Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
neo van matix Posted June 22, 2006 Author Posted June 22, 2006 Okay... Func win($TITLE, $TEXT) IF WinExists($TITLE, $TEXT) Then IF NOT WinActive($TITLE, $TEXT) Then WinActivate($TITLE, $TEXT) EndIf EndIf EndFunc run("sqlnav510.exe") $TITLE = "License Agreement Acceptance" $TEXT = "Please read the license" win($TITLE, $TEXT) WinWaitActive($TITLE, $TEXT) ControlClick($TITLE, $TEXT, "Button2") ; $TITLE = "SQL Navigator 5.1 Installation" $TEXT = "Welcome!" win($TITLE, $TEXT) WinWaitActive($TITLE, $TEXT) ControlClick($TITLE, $TEXT, "Button4") ControlClick($TITLE, $TEXT, "Button1") ; [...] Okay, a little testscript of an automated installation of SQL Navigator 5.1. I start the autoit-script and switch to another application, like the Internet Explorer. In the background, i see the first window with the licence agreement... Now, the script should automatically switch to the Windows - it Exists, and its not active. But nothing happens. If i start a testscript, which only starts the notepad.exe with run() and the parameter SW_HIDE, no Notepad Window opens, but the notepad.exe process still exists. Maybe, this should happens - i dont know. There are no exactly information in the german helpfile.. Attention! English noob ^^
Ravenlark Posted June 22, 2006 Posted June 22, 2006 (edited) I tend to use WinWait and WinActivate for my installation scripts. WinWait justs waits until the window exists in any form, then good old WinActivate activates it. If you use this for every window that requires input, and don't put any delays in the script, the chances are very slim that a new window will steal focus between the WinActivate and the input. To illustrate, here is the start of an Ad-Aware installation script: WinWait("Ad-Aware SE Professional", "Welcome to Ad-Aware SE Professional Setup program") WinActivate("Ad-Aware SE Professional") Send ("n") WinWait("Ad-Aware SE Professional", "I accept the license agreement") WinActivate("Ad-Aware SE Professional") Send ("{TAB}{TAB}") Send ("{SPACE}") Send ("n") WinWait("Ad-Aware SE Professional", "Setup will install Ad-Aware SE Professional in the following folder.") WinActivate("Ad-Aware SE Professional") Send ("n") WinWait("Ad-Aware SE Professional", "The settings for this application can be installed") WinActivate("Ad-Aware SE Professional") Send ("n") WinWait("Ad-Aware SE Professional", "You are now ready to install Ad-Aware SE Professional.") WinActivate("Ad-Aware SE Professional") Send ("n") Edit: I know I should use ControlClick instead of send keys...its an old script. Edited June 22, 2006 by Ravenlark Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain
MHz Posted June 22, 2006 Posted June 22, 2006 expandcollapse popup; When using relative addressing, be sure to ; check the current working directory 1st or use ; fullpaths to ensure success. ; To check current working directory. If @WorkingDir <> @ScriptDir Then FileChangeDir(@ScriptDir) EndIf ; Or use a macro to for a fullpath address. Run(@ScriptDir & "\sqlnav510.exe") $TITLE = "License Agreement Acceptance" $TEXT = "Please read the license" WinWait($TITLE, $TEXT) ControlClick($TITLE, $TEXT, "Button2") $TITLE = "SQL Navigator 5.1 Installation" $TEXT = "Welcome!" WinWait($TITLE, $TEXT) ControlClick($TITLE, $TEXT, "Button4") ControlClick($TITLE, $TEXT, "Button1") ; [...] ; Use the below function for active window requirements ; when using Send and Mouse* functions. ; Control* functions do not require an active window. Func WinWaitActivate($TITLE, $TEXT = "", $TIMEOUT = 3600) IF WinWait($TITLE, $TEXT, $TIMEOUT) Then IF NOT WinActive($TITLE, $TEXT) Then WinActivate($TITLE, $TEXT) EndIf WinWaitActive($TITLE, $TEXT) EndIf EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now