从VBS在同一目录中运行批处理文件 [英] Running a Batch File in the Same Directory from the VBS

查看:163
本文介绍了从VBS在同一目录中运行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应该运行.bat或.vbs文件的VBScript,但是它不起作用! 它出现一个错误,指出无论是否放置文件路径都找不到该文件(无论如何,我认为这并不重要,因为它位于同一目录中).

I have a VBScript that is supposed to run a .bat or .vbs file, but it doesn't work! It comes up with an error saying that the file could not be found, whether i put in a file path or not (it shouldn't matter anyway I think because it's in the same directory).

所以我的问题是,如何从VBScript中启动.bat文件(甚至更好的是.vbs文件)?

So my question is, how do I start a .bat file (or even better, a .vbs file) from within a VBScript?

相关代码如下:

'*******This is the start of my open command that doesn't work*******
Do
    If Hour(Now) >= 9 And Hour(Now) <= 18 And Minute(Now) = 34 And Second(Now) = 59 Then
        Dim shell
        Set shell = CreateObject("WScript.Shell")
        shell.Run "F:\\EAS\Volume Up.vbs"
        Set shell = Nothing
        MsgBox "My De-bug Message Box which doesn' even get to open"
        WScript.Sleep 2000
        Set WshShell = CreateObject("WScript.Shell")
        music = "C:\...\MYFILE.wav"
        WshShell.Run "wmplayer """ & music & """", 0, True
        WScript.Quit 1
    Else
'*******This is the end*******

那么我在做什么错了?是打开它的错误方法吗?我应该放什么呢?

So what am I doing wrong? Is it the wrong way to open it? What should I put instead?

推荐答案

最好查看.BAT文件的内容.

It would be good to see the contents of the .BAT File.

您的代码看起来不错,因为我能够在计算机上运行以下脚本:

Your code seems fine as I am able to run the below script on my machine:

   dim shell
   set shell=createobject("wscript.shell")
   shell.run "tester.bat"

由于测试人员将.BAT文件的末尾添加以下命令,因此您可能看不到.BAT文件正在做什么,因为它是如此之快:

You may not see what the .BAT File is doing as it happens so quickly, as a tester add the following command to the end of your .BAT Script:

pause

然后您将看到命令提示符打开.根据我上面的VB代码,.BAT文件的内容如下:

Then you will see the command prompt open. As per my VB code above, the .BAT file contents are below:

@echo OFF
@echo %time%
pause

这将向您显示当前时间,然后暂停,使命令提示符保持打开状态.试试看,因为它对我来说很好用.

This will show you the current time and then pause, leaving the command prompt open. Give this a go as a tester as it works fine for me.

这篇关于从VBS在同一目录中运行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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