【问题标题】:Chrome: Possible to script like InternetExplorer.Application in VBScript?Chrome:可以在 VBScript 中编写类似 InternetExplorer.Application 的脚本吗?
【发布时间】:2016-05-12 01:39:45
【问题描述】:

我有一个使用 InternetExplorer.Application 登录网站的 VBScript,然后每隔一段时间刷新一次页面,以防止网站因不活动而退出。它位于安装在我们办公室的仪表板屏幕上。有没有办法以类似的方式编写 Chrome 脚本?它不必是 VBScript,任何语言都可以。我们希望停止使用 Internet Explorer。

【问题讨论】:

    标签: google-chrome vbscript


    【解决方案1】:

    您不能将 Google Chrome 控制为 VBscript 中的对象。原因如下:VBScript CreateObject Google Chrome

    话虽如此,您仍然可以在 google chrome 上操作刷新。只需复制要刷新的页面标题,激活页面后,使用 SendKeys 命令使其刷新。例如 (CTRL+R) - 导致刷新,或在 Sendkeys ("^r") 中。

    刷新后,只需将其设置为循环,然后将等待时间设置为您想要的多长时间。

    '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
    

    【讨论】:

      【解决方案2】:

      这是我在js文件中编辑的一种方式,但在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);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-10
        • 1970-01-01
        • 2019-12-05
        • 2010-09-05
        • 2013-03-21
        • 1970-01-01
        • 1970-01-01
        • 2010-10-28
        相关资源
        最近更新 更多