想要使用 VBScript 在不同的文件夹中运行 .bat 文件 [英] Want to use VBScript to run .bat file in a different folder
问题描述
我正在尝试使用 VBScript 运行 .bat 文件.在与 .bat 相同的文件夹中执行时,我可以让 VBScript 工作,但是,我不知道如何在文件夹外成功运行它.
I'm trying to run a .bat file using VBScript. I can get the VBScript to work when executed within the same folder as the .bat, however, I can't figure out how to make it successfully run when outside the folder.
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run "C:UsersjsDesktopcreateIndexcreateindex.bat"
推荐答案
临危受命 我怀疑批处理脚本需要自己的父文件夹作为工作目录.您可以通过将代码更改为以下内容来相应地设置工作目录:
Going out on a limb I would suspect that the batch script requires its own parent folder to be the working directory. You can set the working directory accordingly by changing your code to this:
Set shell = CreateObject("WScript.Shell")
shell.CurrentDirectory = "C:UsersjsDesktopcreateIndex"
shell.Run "createindex.bat"
<小时>
如果以上内容没有帮助,您需要提供更多关于应该发生什么以及实际上发生什么的信息.在可见模式下运行外部命令/脚本而不自动关闭 CMD 通常有助于调试:
If the above doesn't help you need to provide more information about what should happen and what actually does happen. Running the external command/script in visible mode and without automatically closing CMD usually helps with debugging:
shell.CurrentDirectory = "C:UsersjsDesktopcreateIndex"
shell.Run "cmd /k createindex.bat", 1, True
这篇关于想要使用 VBScript 在不同的文件夹中运行 .bat 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!