ShellExecute,路径中有空格

ShellExecute, spaces in path

我需要使用 ShellExecute 从我的 VB6 代码执行外部程序:我面临的问题是,当路径字符串有任何 space 时它不起作用:

Dim Path As String
Path = "E:\PROYECTOS WG\Gama EVO 2\WontaGes\facturae\facturae.jar"
ShellExecute Me.hWnd, "open", "javaw.exe ", "-jar '" & Path & "'", "", 0 

当我 运行 它时,它抛出错误 "Unable to access jar file "E:\PROYECTOS"

但是在CMD(命令行)中我可以运行它

 javaw -jar "E:\PROYECTOS WG\Gama EVO 2\WontaGes\facturae\facturae.jar"

如何解决?

谢谢

试试

Dim Path As String
Path = Chr$(34) & "E:\PROYECTOS WG\Gama EVO 2\WontaGes\facturae\facturae.jar" & Chr$(34)
ShellExecute Me.hWnd, "open", "javaw.exe ", "-jar " & Path, "", 0

Chr$(34) 插入双引号而不是单引号。

路径名用双引号引起来:

Path = ""E:\PROYECTOS WG\Gama EVO 2\WontaGes\facturae\facturae.jar""

并删除 ShellExecute 行中的单引号:

ShellExecute Me.hWnd, "open", "javaw.exe ", "-jar " & Path & , "", 0