Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List all Internet explorer windows in admin mode with CreateObject("Shell.Application").Wi

Status
Not open for further replies.

enelium

Programmer
May 14, 2016
1
FR
Hi,

I need some help on vbscript on the folowing point (on win7,IE11): I have discovered that when creating two (or more) IE object, when going in admin mode, only the first one is seen with CreateObject("Shell.Application").Windows

To give an example of the problem, in the following code i run a sub called IEOpen() that only creates 2 IE object by the usual way and navigate for example to bing and google. Then list those windows by using a loop on CreateObject("Shell.Application").Windows.

The first run is made normally and both windows are detected, but when relaunch the script under admin mode, when recalling the same Sub, only the first IE Object is detected:

Code:
path    = CreateObject("WScript.Shell").CurrentDirectory 

  If WScript.Arguments.length = 0 Then    

     ' First try, running not as admin
      IEOpen

     'relaunch script as admin
      Set ShellApp = CreateObject("Shell.Application")
      ShellApp.ShellExecute "wscript.exe", Chr(34) & _
            WScript.ScriptFullName & " " & Chr(34) & _
            " " & Chr(34) & path &  Chr(34),"", "runas", 1
  Else
      Start
  End If

Sub Start
   'Run same script again but in admin mode
     IEOpen
end sub

Sub IEOpen()
  
    ' Create 2 IE Object
      Set IE1 = WScript.CreateObject("InternetExplorer.Application")
      Set IE2 = WScript.CreateObject("InternetExplorer.Application")
      IE1.Navigate "[URL unfurl="true"]www.bing.com"[/URL]
      IE2.Navigate "[URL unfurl="true"]www.google.com"[/URL]
      IE1.Visible = true
      IE2.Visible = true
  
     ' list all the windows opened, including IE windows:
     ' When runing this sub in admin mode, the ...Windows.count is lower as second IE is not seen

      msgbox CreateObject("Shell.Application").Windows.count

      For Each win In CreateObject("Shell.Application").Windows
           msgbox win.LocationURL
      Next
     
      IE1.Quit
      IE2.Quit
End Sub

In my complete code i need to have 2 differents IE and run as admin, so i'm stuck as i can't access to the properties of the second IE Object. Do you know what i'm doing wrong or if this problem can be bypassed ? Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top