Question

I have a VBScript that uses InternetExplorer.Application to login to a website, then refresh the page every once in a while to keep the website from logging out due to inactivity. This sits on a dashboard screen mounted in our office. Is there a way to script Chrome in a similar way? It doesn't have to be VBScript, any language will do. We are looking to stop using Internet Explorer.

Était-ce utile?

La solution

You can't control Google Chrome as an object in VBscript. Here's why: VBScript CreateObject Google Chrome

That being said, you CAN still manipulate a refresh on google chrome. Just copy the title of the page you want refreshing, and once the page has been activated, use a SendKeys command to cause it to refresh. e.g.(CTRL+R) - causes refresh, or in Sendkeys ("^r").

Once you've got it refreshing, just set it in a loop and set your wait period for however long you want.

'This is an infinite loop, only disposed of by exiting Wscript.exe or Cscript.exe
Do While(true)
Dim PageTitleToRefresh, IntervalinSeconds, x, objShell, Success

'Page Titles - NOT the page address - (google.com = NO) (Google = YES)
'Page Titles are normally stored at the top of the browser or in the tab name of the browser. 
PageTitleToRefresh = "Google"
IntervalinSeconds = 10

x = IntervalinSeconds * 1000
Set objShell = WScript.CreateObject("WScript.Shell")
    Do Until Success = True
        Success = objShell.AppActivate(PageTitleToRefresh)
        Wscript.Sleep 1000
    Loop
    wscript.echo "Activated, now refreshing"
objShell.SendKeys "^r"

Wscript.Sleep IntervalinSeconds
Loop

Autres conseils

here is a way that I edited in js file, but can be also realized in vbs :

var fso = new ActiveXObject("Scripting.FileSystemObject");


var chrome = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
var url = 'http://google.com';

if (fso.FileExists(chrome)){
    var objShell = WScript.CreateObject("Shell.Application");
    objShell.ShellExecute(chrome, "--app="+url, "", "", 1);
}
else{ //if chrome doesn''t exists, so launch ie :
    oIE1 = WScript.CreateObject ("InternetExplorer.Application");

    oIE1.Visible = 1;
    oIE1.AddressBar = 0;
    oIE1.StatusBar = 0;
    oIE1.ToolBar = 0;
    oIE1.MenuBar = 0;
    oIE1.Navigate(url);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top