2014-10-28 38 views
1

我以前幾乎沒有使用過vbscript,所以請原諒我的天真。 這裏很簡單的代碼,保存爲「runningCheck.vbs」:如何在VBS中使用文件名

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

這個腳本是在同一目錄node.exe和index.js。在Windows命令行中,當我進入目錄並運行「runningCheck.vbs」時,它執行得很好。但是,當cd退出目錄並使用完整文件路徑調用相同的vbs腳本時,它不再起作用。
起初,我以爲我只是需要在我的VBS腳本提供完整路徑名,例如:

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) 

,但我得到的錯誤「系統找不到指定的文件。」 如何正確指定路徑名?

在此先感謝幫助!

回答

2

通常,爲.Run和.Exec指定完整路徑是個不錯的主意。如果你想遵循這種做法,你需要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) 

後來想想在a more structured way組織複雜的字符串的建設(命令行,sql語句,......)。