启动路径包含空格的程序 [英] Launch programs whose path contains spaces

查看:30
本文介绍了启动路径包含空格的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 VBScript 在本地系统中启动程序.但是我在语法上遇到了问题.这就是我现在正在使用的 -

I need to launch programs in my local system using VBScript. But I am having trouble with the syntax. This is what I am using right now -

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("iexplore")
Set objShell = Nothing

以上代码成功启动IE.我想启动其他浏览器.但是,如果我使用 -

The above code successfully launches IE. I want to launch other browsers. But, if I use -

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("c:\Program Files\Mozilla Firefox\firefox.exe")
Set objShell = Nothing

它抛出一个错误,说找不到文件或路径.我不确定 Run() 函数中的参数是如何获取的 - 我应该给出 EXE 的路径还是应该给出一些 DOS 命令?!

it is throwing an error saying that the file or path was not found. I am not sure how the parameter inside the Run() function is taken - should I give the path to an EXE or should I give some DOS commands?!

推荐答案

Try:-

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""c:\Program Files\Mozilla Firefox\firefox.exe""")
Set objShell = Nothing

注意字符串中额外的".由于 exe 的路径包含空格,因此需要用引号将其包含在内.(在这种情况下,只需使用firefox.exe"即可).

Note the extra ""s in the string. Since the path to the exe contains spaces it needs to be contained with in quotes. (In this case simply using "firefox.exe" would work).

另请记住,64 位版本的 Windows 上的 c:\Program Files (x86) 文件夹中存在许多程序.

Also bear in mind that many programs exist in the c:\Program Files (x86) folder on 64 bit versions of Windows.

这篇关于启动路径包含空格的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆