[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12201
  • Last Modified:

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

0
abgtemp
Asked:
abgtemp
  • 4
  • 3
1 Solution
 
AmazingTechCommented:
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
0
 
abgtempAuthor Commented:
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

0
 
abgtempAuthor Commented:
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.  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AmazingTechCommented:
Try this instead.

runas /user:administrator "wscript c:\at\ie.vbs"


at 13:00 /interactive cscript C:\at\ie.vbs
Set objShell = CreateObject("Shell.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\test.txt")
 
 
 
Set IE = createobject("internetexplorer.application")
IE.navigate "http://www.microsoft.com"
IE.visible = true
 
do while ie.busy
   wscript.sleep 1000
loop
 
 
Wscript.Echo ie.locationurl
f1.writeline ie.locationurl
 
IE.navigate "http://www.cnn.com"
 
do while ie.busy
   wscript.sleep 1000
loop
 
 
Wscript.Echo ie.locationurl
f1.writeline ie.locationurl
 
f1.close

Open in new window

0
 
abgtempAuthor Commented:
Thanks for the help.  Could you also give me some assistance on another open question that I have.
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23874454.html
0
 
AmazingTechCommented:
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.
0
 
abgtempAuthor Commented:
Thanks for the help. I'm bumping up the points for the quick response
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now