Search code examples
internet-explorerbackgroundwindowuacnsis

How to open a second Internet Explorer window in the background using NSIS


this is a simple question, but can't find an easy answer ...
I am writing a script in NSIS and I need to open two windows in Internet Explorer

So I use ...
UAC::Exec '' '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "$url_1' '' ''
then...
UAC::Exec '' '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "$url_2' '' ''

But I would like the $url_2 to be opened BEHIND/in the background of the one with $url_1
I'm going crazy there... Thanks for any help !

ps. I'm not forced to use UAC::Exec as long as It starts a new IE window.


Solution

  • The answer is pretty simple: just switch order of opening windows:

    UAC::Exec '' '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "$url_2' '' ''
    then...
    UAC::Exec '' '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "$url_1' '' '' 
    

    So the $url_2 will be behind $url_1 because it is opened later...

    Edit

    If you wish to have some exact window in the front you must know it's name (IE set name to window after it is fully loaded).

    Use this simple loop to bring required window in the front. (I used Exec, but works fine with UAC and nsExec)

    ; This Window is opened as first
    Exec '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "www.google.sk"' # $url_1
    ; This is opened later
    Exec '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "www.unsigned-softworks.sk/installer"'  # $url_2
    
    CheckWindow:
      Sleep 500 ; Wait some time (miliseconds)
    
      ; Find by Window class and by Window name 
      FindWindow $1 "IEFrame" "Google - Windows Internet Explorer" 
      # This name must be known in compile time!!!
      # Get this name by running $url_1 in IE
    
      ; If window is not found (not loaded!) search again 
      IntCmp $1 0 CheckWindow Continue Continue
    
    Continue:
      # If found (opened & loaded), bring $url_1 to front
      System::Call "User32::SetForegroundWindow(i) b ($1)"