不能将包含空格的参数传递给vbs函数

时间:2017-04-21 18:08:47

标签: html windows vbscript

    function readFromRegistry (strRegistryKey, strDefault)
    Dim WSHShell, value
     On Error Resume Next
    Set WSHShell = CreateObject ("WScript.Shell")
    value = WSHShell.RegRead (strRegistryKey)
    if err.number <> 0 then
        readFromRegistry= strDefault
    else
        readFromRegistry=value
    end if    
    set WSHShell = nothing
   end function

function OpenWithChrome(sPage)
    Dim strChrome
    Dim WShellChrome  
    strChrome = readFromRegistry ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe\Path", "") 
    if (strChrome = "") then
        strChrome = "chrome.exe"
    else
        strChrome = strChrome & "\chrome.exe"
    end if
    Set WShellChrome = CreateObject("WScript.Shell")
    strChrome = """" & strChrome & """" & " " & sPage
    WShellChrome.Run strChrome, 1, false
  end function  
    OpenWithChrome "auto slides.html"

在最后一行我调用函数OpenWithChrome,参数包含空格。但它无法在我的浏览器中打开该文件。

1 个答案:

答案 0 :(得分:0)

您只需对空间进行编码,以便Chrome了解它。将该行更改为:

OpenWithChrome "auto%20slides.html"

有关编码使用空格的html文件的更多信息,请访问:

HTML: href syntax : is it okay to have space in file name