我想能够从VBS脚本内调用以下cmd命令:

cmd Client\setupclient.exe /q /targetdir "c:\program files\Microsoft CRM"

我想出了以下VBS脚本:

Set oShell = WScript.CreateObject ("WScript.Shell") 
oShell.Run "cmd /c Client\setupclient.exe /q /targetdir c:\program files\Microsoft CRM", 1, true

至于我而言,这会工作,如果正常的TARGETDIR没有空格,e.g C:\喇嘛。然后应用程序将被安装在该特定文件夹。

最明显的问题是,如何可以定义与TARGETDIR空格作为路径位置。结果, 我试图将其包围',但没有为我工作。任何建议?

干杯 克里斯

有帮助吗?

解决方案

与空格的路径通常用引号字符(")。在VBScript中,插入一个引号字符到使用双引号("")的字符串。所以,你的代码应该是这样的:

oShell.Run "cmd /c Client\setupclient.exe /q /targetdir ""c:\program files\Microsoft CRM""", 1, true

另外,我不知道是否确实需要在这里cmd /c,所以它可能以这种方式工作,以及:

oShell.Run "Client\setupclient.exe /q /targetdir ""c:\program files\Microsoft CRM""", 1, true

其他提示

我结束了

AMPath = "E:\Program Files (x86)\Dropbox\Client\Dropbox.exe"
If FileSyst.Fileexists(AMPath) Then 
 AMPath = chr(34) & AMPath & chr(34)
OBJ_Shell.run (AMPath)
End If 

1,如果你的操作系统支持8.3文件名,可以尝试短文件名:

cd c:\
dir /x
2017/04/17  20:53    <DIR>          PROGRA~1     Program Files
2017/04/18  03:40    <DIR>          PROGRA~2     Program Files (x86)

然后repalce C:\ Program Files文件\与PROGRA〜1

2时,使用完整路径中的两个双引号。

WScript.CreateObject("WScript.Shell").Run """C:\Program Files\DirName\FileName.exe"" /option1 value1 /option2 vaule2 argv3"

这是不完全的问题所描述的,在该被调用的程序,而不是一个参数包含的空间中。谷歌搜索“whshell.run不工作,如果文件名包含空格,”让我在这里。

当被调用的程序包含其名称的空间中,它需要被引用三倍。 (起始和结束引号定义与坯料和封闭双引号的字符串被映射到串中的单引号。)有两种工作实施例。第一种使用三重引号。第二个有效地从名称的空白。非工作实例表明什么不该做(也是我第一次尝试。)

' Drive D:\Program Files\Batch\Monitor.bat with no associated command window

Set WshShell = CreateObject("WScript.Shell")

' These methods work: (Select one)
  Return = WshShell.Run("""D:\Program Files\Batch\Monitor.bat""", 0)
' Return = WshShell.Run("D:\.D-DISK\Monitor.bat", 0)
' Note: Here "D:\.D-DISK\Monitor.bat" is a symbolic link to
'       "D:\Program Files\Batch\Monitor.bat"

' The following methods fail because of the space in the filename.
' WshShell.Run( chr(34) & D:\Program Files\Batch\Monitor.bat & Chr(34), 0 )
' Return = WshShell.Run("D:\Program Files\Batch\Monitor.bat", 0)
' Return = WshShell.Run(""D:\Program Files\Batch\Monitor.bat"", 0)

Set WshShell = Nothing
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top