Opening browser on a variable page using vbscript

前端 未结 4 674
猫巷女王i
猫巷女王i 2020-12-11 07:24

I\'m trying to write a bit of VBScript to open a browser on a specific webpage. Ultimately this webpage would be unique per script. At the moment I have the following code w

相关标签:
4条回答
  • 2020-12-11 07:44

    No As String as VBScript is not strongly type, you need a set when you create an instance of the COM object & no parens around the method call;

    Dim iURL 
    Dim objShell
    
    iURL = "www.google.ie"
    
    set objShell = CreateObject("Shell.Application")
    objShell.ShellExecute "chrome.exe", iURL, "", "", 1
    

    Or if chrome is the default

    set objShell = CreateObject("WScript.Shell")
    objShell.run(iURL)
    
    0 讨论(0)
  • 2020-12-11 07:55
      Sub RickRoller()
       Dim counter, myNum, objShell, iURL
       counter = 0
       myNum = 100
       Do Until myNum = 1
         myNum = myNum - 1
         counter = counter + 1
         Set WshShell = CreateObject("WScript.Shell")
         WshShell.SendKeys(chr(&hAF))
       Loop
       set objShell = CreateObject("WScript.Shell")
       iURL = "https://youtu.be/oHg5SJYRHA0?autoplay=1&t=44"
       objShell.run(iURL)
     End Sub
    
    
     RickRoller()
    
    0 讨论(0)
  • 2020-12-11 07:59

    Can you pl insert "Call" prefix to "objShell.ShellExecute"

    Dim objShell
    Set objShell = CreateObject("Shell.Application")
    
    iURL = "www.google.com"
    
    Call objShell.ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", iURL, "", "", 1)
    

    For IE:

    'Call objShell.ShellExecute("iexplore.exe", iURL, "", "", 1)
    
    
    For more info below code also works,
    
    Dim objShell
    Set objShell = CreateObject("Shell.Application")
    

    chrome:

    iURL = "www.google.com"
    'objShell.ShellExecute "chrome.exe", iURL, "", "", 1
    

    ie:

    'objShell.ShellExecute "iexplore.exe", iURL, "", "", 1
    
    0 讨论(0)
  • 2020-12-11 07:59

    I found the easiest way is to do this:

    set WshShell=WScript.CreateObject("WScript.Shell")
    WshShell.run "chrome.exe"
    WScript.sleep 400
    WshShell.sendkeys "URL HERE"
    WshShell.sendkeys "{ENTER}"
    

    also just a fyi you can do this to close chrome:

    WshShell.sendkeys "%{F4}"
    
    0 讨论(0)
提交回复
热议问题