想要使用VBScript在不同的文件夹中运行.bat文件

jod*_*ies 7 vbscript batch-file

我正在尝试使用VBScript运行.bat文件.我可以在与.bat相同的文件夹中执行时使VBScript工作,但是,我无法弄清楚如何在文件夹外部成功运行它.

Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run "C:\Users\js\Desktop\createIndex\createindex.bat"
Run Code Online (Sandbox Code Playgroud)

Ans*_*ers 9

走出困境,我怀疑批处理脚本需要自己的父文件夹作为工作目录.您可以通过将代码更改为此来相应地设置工作目录:

Set shell = CreateObject("WScript.Shell")
shell.CurrentDirectory = "C:\Users\js\Desktop\createIndex"
shell.Run "createindex.bat"
Run Code Online (Sandbox Code Playgroud)

如果上述不帮助你需要提供什么信息应该发生的和实际发生.以可见模式运行外部命令/脚本而不自动关闭CMD通常有助于调试:

shell.CurrentDirectory = "C:\Users\js\Desktop\createIndex"
shell.Run "cmd /k createindex.bat", 1, True
Run Code Online (Sandbox Code Playgroud)