代码之家  ›  专栏  ›  技术社区  ›  Zhili

shell.run ws.currentdirectory+“\somepath\chrome.exe--app=https://a.com”现在可以工作[复制]

  •  0
  • Zhili  · 技术社区  · 7 年前

    这个问题已经有了答案:

    我想要一个vbs来打开chrome并加载一个特定的url,但是当目录包含空格时它就不工作了。

    我的代码,参考 shell.run with variable ,不起作用。我刚收到一个错误窗口说

    系统找不到特定文件。错误代码:80070002

    Set Ws = CreateObject("WScript.Shell")
    chromeLuncher = Ws.CurrentDirectory + "\Chrome\Application\chrome.exe --app=https://www.google.com --start-maximized"
    Ws.Run DblQuote(chromeLuncher), 1, True
    
    '****************************************
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '****************************************
    

    我该怎么解决?

    更新1:

    文件夹的结构:

    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d-----         2018/6/4     10:42                Chrome
    -a----         2018/6/4     15:23            190 fso.vbs
    

    铬的结构:

    Chrome
     └─Application
        ├─61.0.3163.100
        │  ├─default_apps
        │  ├─Extensions
        │  ├─Installer
        │  ├─Locales
        │  ├─swiftshader
        │  ├─VisualElements
        │  └─WidevineCdm
        ├─Dictionaries
        ├─plugins
        ├─SetupMetrics
        └─chrome.exe
    

    更新2:

    我试过密码 How to call Run() with parameters ,将我的代码更改为:

    Set Ws = CreateObject("WScript.Shell")
    chromeLuncher = """Ws.CurrentDirectory"" + ""\Chrome\Application\chrome.exe --app=https://www.google.com --start-maximized"""
    Ws.Run chromeLuncher,1,True
    Ws = Nothing
    

    但还是有同样的错误:

    the error

    1 回复  |  直到 7 年前
        1
  •  0
  •   Mihai Adrian    7 年前

    请尝试以下代码:

    Dim myURL 
    Dim objShell
    Set Ws = CreateObject("WScript.Shell")
    
    myURL = "https://www.google.com"
    
    set objShell = CreateObject("Shell.Application")
    objShell.ShellExecute Ws.CurrentDirectory+"\chrome.exe.lnk", myURL, "", "", 3
    set objShell = nothing
    

    你可以调试你的代码,你会发现你为chrome指定的路径是错误的,这就是你在第3行收到错误的原因。

    ShellExecute方法的文档:

    https://msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx

    编辑:您可以将chrome.exe安装文件夹的快捷方式放在vbs脚本的当前文件夹中。