How to use filenames in VBS [duplicate]

梦想的初衷 提交于 2019-12-24 07:34:13

问题


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)

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?

Thanks in advance the help!


回答1:


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.

So try:

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)

Then think about organizing the building of complex strings (command lines, sql statements, ...) in a more structured way.



来源:https://stackoverflow.com/questions/26614534/how-to-use-filenames-in-vbs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!