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

x
?
Solved

Bat File - Focus and Refresh IE

Posted on 2011-10-18
10
Medium Priority
?
3,566 Views
Last Modified: 2012-05-12
I don't know if this is possible, but doing some googles didn't return much result.  I want to create a bat file that I will schedule to run every 30 minutes.  I want this bat file to focus on Internet Explorer, do a Refresh, and finall an Enter key and then close.

Basically, I have a reporting services that requires some parameters.  Each time I hit "F5" to refresh it would error out.  I have a user that would like to have the report refresh every 30 minutes so he can get most up to date info without having to do it every 30 minutes or so.   I was thinking that if I can get a bat file to focus on IE and refresh the page, it would fix his problem.  Only issue is that since there are some parameters involve, it would error out if I hit "F5".  

Error is:  The page cannot be refreshed without resending the information.  Click retry to send the information again, or click cancel to return to the page that you were trying to view.

So I was hoping that a bat file can be set to focus on IE, hit F5, and then either hit "R" or "enter" key to get rid of the error.  If it does it quick enough, it would be seamless to the user other than his browser refreshing every 30 minutes.

So anyone might be able to help with such a script or point me to something that I can use as an example to get started?  Criteria is focus on IE, hit "refresh" or "F5", and then hit "R" or "Enter" key.  If there's a better way, that'll be even better.  Thanks in advance.
0
Comment
Question by:holemania
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 8

Expert Comment

by:jawa29
ID: 36987423
Hi

Is this a page you have control over? If it is then you can add this to the HTML.

<meta http-equiv="refresh" content="5">

Open in new window


content="5" is seconds.

This would refresh the page from the server end and not require the content to be re-submitted.

Jawa29
0
 

Author Comment

by:holemania
ID: 36988603
I don't have control over this page.  The report is from reporting services.  If the report has no parameters, it can be set to execute at different interval.  The issue is that with parameters, you can't set it to execute without defaulting.  The user can put in any value they want for the parameter.

My thoght was to focus on IE and then refresh.  However, with the parameter when refreshing it pop up with that error.  So if it can be set to do some keystrokes in sequence, it will resolve the pop up as well.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36989118
AutoIt might be your option here:

http://www.autoitscript.com/site/autoit/downloads/

You can setup a simple script to watch for the IE window title, send the F5 key perioidcally etc. in text editor then either have Autoit installed on this computer and run the .au* file or you can compile it into an exe and run it on anything.

Works great... used it for years!

You may also be able to get away with using VBScript and Sendkeys

Steve
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 39

Expert Comment

by:BillDL
ID: 36991130
I haven't tested this, but in theory it should work.  How about loading the page over which you have no control into a separate frame of its own in a local page over which you do have control of the code.  Add a "Meta Refresh" in the local HTML file which should then reload the page from the Internet as well?  If the user needs the page to reload every 30 minutes, then I would have thought that he/she would have been there to just click the "Retry" button in the message box as it happens.
0
 

Author Comment

by:holemania
ID: 36992264
Thanks for the inpute all.  Yes, vbscripting might be the path to go.  Although I'm not too great with VBScripting, I"m not sure if it's possible to focus on IE.  I'm sure the keypress is possible.  Just the focusing part.  Anyone with vbscripting background can assist?

BillDL, I think that might be an option.  Although if I hit refresh, I still get the "Retry" message pop-yo.  The entire idea is to avoid having the user to click on this every 30 minutes.  He is not sitting there waiting to refresh it every 30 minutes.  However, he wants the information to refresh every 30 minutes so that whenever he looks at the data it is up to date.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36992457
Give autoit a try if you can :-)
0
 
LVL 8

Accepted Solution

by:
jawa29 earned 1200 total points
ID: 36992582
Hi

This can be done in a VBScript but you have to know the entire title of the IE Window (which can be found by running Task Manager) or in the top left hand corner of IE on older IE versions.

Change Window Title to your required IE title as describe above.

Jawa29
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.AppActivate "Window Title - Windows Internet Explorer"

WshShell.SendKeys "{F5}"
WScript.Sleep 300
WshShell.SendKeys "{ENTER}"

Open in new window

0
 
LVL 29

Assisted Solution

by:matrixnz
matrixnz earned 800 total points
ID: 36995289
I'd also second AutoIT, personally I'd use the script to open the page or attach to the page, then refresh it, you really don't want to take focus of the window, otherwise the user may become annoyed if working in something else and then the browser becomes the focused application.  Also have you tried a Ctrl Refresh?  Examples below will send the refresh without taking focus of the window, it's set to refresh every 5 minutes , just need to change URL.

Example 1 - Using Control Refresh
#include <IE.au3.>
$oIE = _IECreate("http://www.xtra.co.nz", 0, 1, 1, 1)
$begin = TimerInit()

While 1
  Sleep(1000)
    $dif = TimerDiff($begin)
    If $dif > (5 * 60 * 1000) Then
      $hwnd = _IEPropertyGet($oIE, "hwnd")
        ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "^{F5}")
      $begin = TimerInit()
    EndIf
WEnd

Open in new window


Example 2 - Using Refresh + Enter
#include <IE.au3.>
$oIE = _IECreate("http://www.xtra.co.nz", 0, 1, 1, 1)
$begin = TimerInit()

While 1
  Sleep(1000)
    $dif = TimerDiff($begin)
    If $dif > (5 * 60 * 1000) Then
      $hwnd = _IEPropertyGet($oIE, "hwnd")
        ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{F5}")
        Sleep(1000)
        ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{ENTER}")
      $begin = TimerInit()
    EndIf
WEnd

Open in new window

0
 

Author Closing Comment

by:holemania
ID: 37027891
Thank you.  Both worked well.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37028014
Oh well guess I should have written the scripts in full rather than just suggesting using Autoit or sendkeys before someone else wrote it...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question