如何在 VBS 中使用文件名 [英] How to use filenames in VBS

查看:32
本文介绍了如何在 VBS 中使用文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前几乎没有使用过 vbscript,所以请原谅我的天真.这是非常简短的代码,保存为runningCheck.vbs":

I've barely ever used vbscript before, so forgive my naivety. Here is very brief code, saved as "runningCheck.vbs":

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("node.exe index.js", 2, true)

此脚本与 node.exe 和 index.js 位于同一目录中.在 Windows 命令行中,当我 cd 进入目录并运行runningCheck.vbs"时,它执行得很好.但是,当 cd 退出目录并使用其完整文件路径调用相同的 vbs 脚本时,它不再起作用.
起初我虽然只需要在我的 vbs 脚本中提供完整的路径名,如下所示:

This script is in the same directory as node.exe and index.js. In windows command line, when I cd into the directory and run "runningCheck.vbs", it executes just fine. However, when cd out of the directory and call the same vbs script with it's full filepath, it does not work anymore.
At first I though I just needed to provide the full path name in my vbs script, like so:

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("C:\Users\computeruser\Building Intelligence\javadobe\node.exe C:\Users\computeruser\Building Intelligence\javadobe\index.js", 2, true)

但我收到错误系统找不到指定的文件".如何正确指定路径名?

but I get the error "the system cannot find the file specified." How do I correctly specify the pathname?

在此先感谢您的帮助!

推荐答案

一般来说,为 .Run 和 .Exec 指定完整路径是个好主意.如果你想遵循这种做法,你需要引用像专业人士.

In general, specifying full pathes for .Run and .Exec is a good idea. If you want to follow this practice, you need to quote like a pro.

那就试试吧:

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("""C:\Users\computeruser\Building Intelligence\javadobe\node.exe"" ""C:\Users\computeruser\Building Intelligence\javadobe\index.js""", 2, true)

然后考虑以更结构化的方式组织复杂字符串(命令行、sql 语句等)的构建.

这篇关于如何在 VBS 中使用文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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