想要使用VBScript在其他文件夹中运行.bat文件 [英] Want to use VBScript to run .bat file in a different folder

查看:102
本文介绍了想要使用VBScript在其他文件夹中运行.bat文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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:\Users\js\Desktop\createIndex\createindex.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:\Users\js\Desktop\createIndex"
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:\Users\js\Desktop\createIndex"
shell.Run "cmd /k createindex.bat", 1, True

这篇关于想要使用VBScript在其他文件夹中运行.bat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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