Automatic F5'er

Sometimes there's a need to just hit 'Refresh' again and again until whatever it is you are doing is complete.

Today, I found myself requiring exactly this kind of Mechanical Turk operation.  I was monitoring the progress of a SQL Server RESTORE operation by keeping an eye on the 'percent_complete' column in sys.dm_exec_requests.

Unfortunately, this does require banging the F5 key again and again, since SSMS doesn't refresh query output automatically.

Here's my eight-line quick n' dirty solution that will work in any version of Windows.  First, you'll need to create a new file with the following contents and the file extension .vbs.  I've called mine f5er.vbs:

Set ws = WScript.CreateObject("WScript.Shell")
    ws.SendKeys "{F5}"
    WScript.Sleep 10000 

Now, create another file with the following contents and the extension .bat.  Make sure that you reference the filename you just created.  Mine is called f5er_go.bat:

@echo "Pressing F5.  Interval: 10 seconds"
cscript /nologo f5er.vbs

To start it, simply open a command prompt and type the name of the .bat file you just created and hit Enter.

Now, you can change focus to any other window.  Every 10 seconds, the F5 key will be pressed for you.  If you change focus to SSMS, you can therefore execute your query again, and again, and again, and....  leaving you free to drink coffee and reflect on how long your restore operation is taking.  Or maybe that's just me.


Popular Posts