Jump to content
Sign in to follow this  
StMaSi

Target untitled window...

Recommended Posts

StMaSi

I'm trying to write an AutoIt script that will launch a program, wait for a specific window to appear, then click a button or forceably close said window. However, as the window doesn't have a title, I can't seem to target it. I've tried using the text in the window, window or control classes, and even handle (but the handle changes every time it runs), but nothing I do seems to work. Does anyone have any ideas about how to target this elusive window? Thanks.

Here's the window information from the Summary tab:

>>>> Window <<<<

Title:    
Class:    #32770
Position:    276, 338
Size:    479, 120
Style:    0x94C801C5
ExStyle:    0x00010101
Handle:    0x001F01D2

>>>> Control <<<<
Class:    
Instance:    
ClassnameNN:    
Name:    
Advanced (Class):    
ID:    
Text:    
Position:    
Size:    
ControlClick Coords:    
Style:    
ExStyle:    
Handle:    

>>>> Mouse <<<<
Position:    656, 354
Cursor ID:    0
Color:    0x7D9BE3

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
OK
System.NullReferenceException: Object reference not set to an instance of an object.
   at Utilities.Installation.CustomActions.CustomAction.PromptWASRestart(Int32 handle)

>>>> Hidden Text <<<<
 

Share this post


Link to post
Share on other sites
StMaSi

The main program is a running MSI, being run with msiexec from the CMD line, so I can see that, but this window that appears, doesn't show up at all in task manager and I can't find any new processes being created when this window appears. Thanks.

Share this post


Link to post
Share on other sites
JLogan3o13

Just out of curiosity, if you are running an MSI, why not do a silent install and avoid the headache?

Otherwise, I would suggest using WinList to get a list of all active windows, and see what that returns.


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
StMaSi

Yes, I am running a silent install, but this window appears during the install and the installer hangs indefinitely until either the [OK] button is clicked, or the msiexec process is killed. Unfortunately, if I kill the main msiexec process, the installer doesn't complete successfully. I have used WinList, but the window is a ghost window...it just doesn't show up. I've never seen anything like this before. Thanks again.

Share this post


Link to post
Share on other sites
BrewManNH

You could try getting it using WinGetHandle and looking for the text in the window instead of using the title set it to blank.

$somevariable = WinGetHandle("", "System.NullReferenceException: Object reference not set to")
WinClose($somevariable)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
StMaSi

That last bit of code seems to have done the trick...

Opt("WinDetectHiddenText",1)
Opt("WinSearchChildren",1)
$somevariable = WinGetHandle("", "System.NullReferenceException: Object reference not set to")
WinActivate($somevariable)
WinClose($somevariable)

However, it doesn't seem to matter how I tell the script to wait (winwait, while/wend, etc.), the script just fires off and then terminates. I guess the best way to handle this would be to launch the installer from this script (run), then wait for the aforementioned window to show, then execute the above code. Is there a method or function that I don't know about that would work for this waiting period? Thanks again.

Share this post


Link to post
Share on other sites
BrewManNH

You could use an AdLibRegister function to check for the window every second or so and if it finds it, closes it. This wouldn't interrupt the main script, but will continually monitor for the window to appear.

Something like this might do the trick.

; put this somewhere before your Run command line
AdlibRegister("_MonitorFunc") ; <<<<< This will call the _MonitorFunc function every 250ms (default setting)
; this part can go at the end of the script
Func _MonitorFunc()
    $somevariable = WinGetHandle("", "System.NullReferenceException: Object reference not set to") ; <<<<<<<< try to get the handle to the window
    If Not @error Then ; If @error is 0 (meaning it found the window), then close the window below
        WinActivate($somevariable)
        WinClose($somevariable)
    EndIf
EndFunc   ;==>_MonitorFunc

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
StMaSi

So, I tried the AdlibRegister code, but the AutoIt script started and stopped almost immediately...it didn't wait.

Opt("WinDetectHiddenText",1)
Opt("WinSearchChildren",1)

AdlibRegister("_MonitorFunc") ; <<<<< This will call the _MonitorFunc function every 250ms (default setting)

Run(@ComSpec & " /c " & '"{program.bat}"', "", @SW_HIDE)

Func _MonitorFunc()
    $somevariable = WinGetHandle("", "System.NullReferenceException: Object reference not set to") ; <<<<<<<< try to get the handle to the window
    If Not @error Then ; If @error is 0 (meaning it found the window), then close the window below
        WinActivate($somevariable)
        WinClose($somevariable)
    EndIf
EndFunc   ;==>_MonitorFunc

As for the PID method, the only PID that is present is for the installer...the secondary window that pops up doesn't present with a PID. Yes, I could kill the PID for the main installer, but then that kills the install of the software package, so that won't work.

As for the simple WinWaitActive command, nope...that doesn't work either. It functions just like the code above...the AutoIt script starts, then immediately stops.

Thank you all for all the help you've given me. I've used AutoIt for so many different things in the past, so I'm surprised that something that seems so simple is really throwing me for a loop. Unless there's any other methods available to script this and make it invisible to the end user, I'll just have to touch over 3,000 machines in order to get this software package to complete. Thanks again.

Edited by StMaSi

Share this post


Link to post
Share on other sites
BrewManNH

You need something to keep the script open while the installation is going on.

Opt("WinDetectHiddenText", 1)
Opt("WinSearchChildren", 1)

AdlibRegister("_MonitorFunc") ; <<<<< This will call the _MonitorFunc function every 250ms (default setting)

$PID = Run(@ComSpec & " /c " & '"{program.bat}"', "", @SW_HIDE)

While ProcessExists($PID)
    Sleep(100)
WEnd
Func _MonitorFunc()
    $somevariable = WinGetHandle("", "System.NullReferenceException: Object reference not set to") ; <<<<<<<< try to get the handle to the window
    If Not @error Then ; If @error is 0 (meaning it found the window), then close the window below
        WinActivate($somevariable)
        WinClose($somevariable)
    EndIf
EndFunc   ;==>_MonitorFunc

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
StMaSi

Dang! Still just started and stopped less than a second later.

Share this post


Link to post
Share on other sites
StMaSi

Dang! Still just started and stopped less than a second later.

And this time, the installer didn't run.

Share this post


Link to post
Share on other sites
BrewManNH

Try adding a 2 second sleep in between the Run command and the While, let the program have time to start before it starts looking for it. There's no error checking with that snippet, so you can also start there to see if the run command returns anything like an error.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
StMaSi

A combination of WinWait and the other code seems to have done it!

Opt("WinDetectHiddenText", 1)
Opt("WinSearchChildren", 1)

AdlibRegister("_MonitorFunc") ; <<<<< This will call the _MonitorFunc function every 250ms (default setting)

$PID = Run(@ComSpec & " /c " & '"program.bat"', "", @SW_HIDE)

WinWaitActive("Windows Installer","Preparing to install...", 300)

While ProcessExists($PID)
   Sleep(100)
WEnd

Func _MonitorFunc()
   $somevariable = WinGetHandle("", "System.NullReferenceException: Object reference not set to") ; <<<<<<<< try to get the handle to the window
   If Not @error Then ; If @error is 0 (meaning it found the window), then close the window below
      WinActivate($somevariable)
      WinClose($somevariable)
   EndIf
EndFunc   ;==>_MonitorFunc

Thanks again for all your help!!!

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  

×