refresh firefox from .bat file/ command - firefox

I am attempting to refresh Firefox whenever a bat file is called. I Dont want an extension. I need to know if there is a command that can be used from within a .bat file to reload the current browser or tab.
I know you can use
start firefox as a command but this simply opens a new firefox instance. I need to refresh the current instance.

I was just messing around and came up with this half-working solution that might help a little. Create a file called something like refresh.vbs and paste this in:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate("Google Chrome")
WScript.Sleep 500
WshShell.SendKeys "{TAB}"
WScript.Sleep 100
WshShell.SendKeys "{F5}"
I could only test it with Chrome. The script activates Chrome, sends a tab, and then sends F5 to refresh. It works when I have Chrome up showing one web page, but not when there are multiple web tabs open (because AppActivate activates the Window, but does not give focus to anything).
Maybe it works better with Firefox. There's probably some way to enumerate the tabs in a browser and activate it in vbs, but I don't know it.
If you spawn the browser within the vbs (see WshShell.Run, and the example in the SendKeys documentation), you can get the process number and send messages directly to that Window instead of relying on the app title.
You can invoke the .vbs from within a batch file if you need to:
#echo off
refresh.vbs

On Error Resume Next
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate "http://www.microsoft.com/technet/scriptcenter"
objExplorer.Visible = 1
Wscript.Sleep 5000
Set objDoc = objExplorer.Document
Do While True
Wscript.Sleep 30000
objDoc.Location.Reload(True)
If Err <> 0 Then
Wscript.Quit
End If
Loop

Related

Open as active window

I am trying to create a very simple vbscript that opens a browser to a specific webpage then refreshes. The problem I am having is trying to make the browser the active window, I have searched various sites and tried various forms of appactivate but with no success. I normally don't work with VBS so I might be missing something super obvious, Please see below for what I have so far
set wshShell = WScript.CreateObject("wscript.shell")
wshShell.Run("http://www.example.com")
wshell.senkeys "{F5}"
I would be very grateful for any assistance.
You can use "AppActivate" and you need to wait for the response:
set wshShell = WScript.CreateObject("wscript.shell")
wshShell.Run("http://www.example.com")
Wscript.Sleep 1000
wshShell.AppActivate "Firefox" 'here put the name of the window
Wscript.Sleep 1000
wshell.senkeys "{F5}"

Create a VB script to send the keys to open up a program with specific settings

I am trying to create a VB script to send the keys to open up a program/application with specific settings. So, after the application has been started, choosing those very specific settings would involve pressing 2 buttons inside the application UI (1st button to choose specific set of options, and 2nd button to save those options).
I will then create a batch file to call the mentioned VB script on boot.
So far, I got this:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^%1"
I've searched and searched, but couldn't figure out how to be able choose/save options once the app has been started, if it's even possible?
Thank you in advance for helping out!
Disclaimer: I am not a technical person, so forgive me if noob question :)
Here's a script to start an application (notepad), then send some keystrokes to it:
'VBScript Example
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "c:\windows\notepad.exe"
' add delay here
WshShell.AppActivate "Notepad"
WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "abc"
WshShell.SendKeys "{CAPSLOCK}"
WshShell.SendKeys "def"
Perhaps this can be adapted to your needs?
The WshShell.AppActivate command is used to bring the program (with the specified window title) to the foreground.
You might want to add a delay to allow the program time to start before sending the keystrokes. This can be done by adding a sleep() call just after Wshell.Run:
' Sleep for 5 seconds (5000 msec)
WScript.Sleep(5000)
Also, here's a list of key-codes that you can use.

WScript.Shell SendKeys not working on Windows 8.1 x64

I'm having problems with the following VBScript.
I'm trying to send keystrokes to a web browser window, but nothing happens.
The first two lines in the following script works fine, but the third line with the SendKeys command, doesn't do anything.
Set objShell = CreateObject("WScript.Shell")
objShell.Run "http://someurl.com", 1
objShell.SendKeys "Some Text"
I've tried to run the script on two different Win 8.1 machines. On Win 8.1 Pro it works, but on Win 8.1 not-Pro it won't work. Is there any setting somewhere in Windows that needs to be set or anything other that can help me?
Update
New code tried (added sleep and running browser explicit), but still no luck
Set ObjShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files\Internet Explorer\iexplore.exe""http://someurl.com/"
WScript.Sleep 5000
objShell.SendKeys "Some Text"
While its admittedly not a great programming technique, place a Sleep command after your objShell.Run line (as shown below) to give the OS some time to "catch up" and actually run the URL, activate the browser window to give it focus (you have to take note of the title in the Browser window and use that title exactly), because I have seen the browser window lose focus in some cases and then text cannot be piped into it, and finally it sends the text. Your mileage may vary, and you might even have to increase the sleep time in order to be successful. I've had to sleep up to 30 seconds, in some cases. Especially where, for whatever reason, the web page was slow to render - due to network latency, slow OS, etc.. I haven't faced this problem on Windows 8.1 because I haven't tried it on that platform. I don't think this has anything to do with the OS version; I have faced this same problem with SendKeys on other Windows OS versions where I've had to use the Sleep function like this. The SendKeys method has known limitations, and as it runs outside of the browser you have to wait for certain actions to complete before you can have it do more actions.
Set ObjShell = WScript.CreateObject("WScript.Shell")
objShell.Run "http://someurl.com", 1
WScript.Sleep 20000
objShell.appactivate("Welcome to SOMEURL.COM! - Mozilla Firefox")
WScript.Sleep 700
objShell.SendKeys "Some Text"
Also, you might try replacing line 2 in the above to the following, to see if you have better luck. In the example below, Firefox is the default web browser. Change the path accordingly to the browser of your choice:
objShell.Run("""C:\Program Files\Mozilla Firefox\firefox.exe""http://someurl.com")

Batch file to switch between browser tabs

I have two browser tabs running monitoring applications on a screen. I want to automate switching between tabs after lets say every 2 mins. I think this can be achieved by creating a scheduled task in windows which execute a batch file every 2 mins. Batch file will switch the tab. I need help creating such batch file. Thanks.
You can use VBScript to do that,
Example for IE :
Create a file Switch.vbs with this :
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Internet Explorer"
Wscript.Sleep 1500
WshShell.SendKeys "^{TAB}"
Wscript.Sleep 1500
After opening your 2 tabs in IE run the command every 2 minutes :
wscript.exe switch.vbs

Need a startup script in windows to send ALT+F11 keys?

We are using a shared desktop on thin clients. By default it comes with windowed screen, but by pressing the Alt + F11 keys it will restore to full screen. So, we want a script to execute at Windows log-on with some delay.
Hopefully a login vbscript will work for you. Either append this to an existing login script or save it as a ".vbs" file. Microsoft has some good tutorials if you are unfamiliar with login scripts.
Set WshShell = CreateObject("Wscript.Shell") 'Create wshell object
WScript.Sleep(5000) 'Lets wait 5 seconds
WshShell.AppActivate "EXACT TITLE OF THE WINDOW YOU WANT" 'EDIT THIS LINE!
'The line above selects the window so we make sure the keystrokes are sent to it
WshShell.SendKeys "%{F11}" 'Send ALT+F11
Wscript.Quit 'Quit the script

Resources