Link to home
Start Free TrialLog in
Avatar of abgtemp
abgtempFlag for United States of America

asked on

VBscript find open Internet Explorer window

I am running the script below through a remote scheduler. When this script runs, the script runs as user "SYSTEM". This in turn also opens Internet Explorer under the "SYSTEM" user.

Here is my problem, if I am logged on to the computer, the script does not work correctly. The script does not see the IE window if it is started by "SYSTEM" user. It only sees the IE Window if it is started by the current logged on user. I ran it manually and it worked because it starts the IE process as me and I was the one who was logged on.

Is there any way this script could see the IE Window if it is started by a user other than the one currently logged on? Thanks in advance.
set IE = createobject("internetexplorer.application")
IE.navigate "http://www.site.org"	
IE.visible = true
 
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
 
For i = 0 to objShellWindows.Count - 1
    Set objIE = objShellWindows.Item(i)
    strURL = objIE.LocationURL
    If strURL = "http://www.site.org" Then	
     'Perform Task
end if
Next

Open in new window

Avatar of AmazingTech
AmazingTech

The script or the logged on user doesn't see IE.

Try running the scheduler in interactive mode. The easiest is to use AT to schedule the task.

AT \\RemoteComputer hh:mm /interactive cscript c:\site.vbs
Avatar of abgtemp

ASKER

Thanks for the quick reply. The script doesn't see IE.  The thing is, I can actually see Internet Explorer open, but the script does not.  Run the following script manually first, then run it using the command (AT  hh:mm /interactive cscript c:\site.vbs. You can see what I am talking about.
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
 
 
Set IE = createobject("internetexplorer.application")
IE.navigate "http://www.microsoft.com"       
IE.visible = true
wscript.sleep 3000 
 
If objShellWindows.Count = 0 Then
    Wscript.Echo "No browser windows are open."
    Wscript.Quit
End If
 
blnFound = False
 
For i = 0 to objShellWindows.Count - 1
    Set objIE = objShellWindows.Item(i)
    strURL = objIE.LocationURL
    If InStr(strURL, "http://www.microsoft.com")Then
        blnFound = True
    End If
Next
 
If blnFound Then
    Wscript.Echo "At least one browser window is open."
Else
    Wscript.Echo "No browser windows are open."
End If

Open in new window

Avatar of abgtemp

ASKER

That probably wasn't the best way to test this. The only way I could simulate this error was creating another user on my computer. Then using the RUNAS command, start the the script as that other user. The script does not see the IE window when it was ran as a user other than the one logged on.  
ASKER CERTIFIED SOLUTION
Avatar of AmazingTech
AmazingTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abgtemp

ASKER

Thanks for the help.  Could you also give me some assistance on another open question that I have.
https://www.experts-exchange.com/questions/23874454/Mark-email-as-High-Importance-in-vbscript.html
Did one of these solutions work for you here? If it did can you select which one and close this question if it has been answered.

I'll take a look at your other question.
Avatar of abgtemp

ASKER

Thanks for the help. I'm bumping up the points for the quick response