【问题标题】:Calling .VBS files automatically自动调用 .VBS 文件
【发布时间】:2012-12-17 04:04:46
【问题描述】:

我有 4 个 .vbs 文件,例如 A.VbS、B.VBS、C.VBS、D.VBS。我想按以下顺序称呼他们:

        (1)A.VBS
        (2)B.VBS
        (3)C.VBS
        (4)D.VBS

当第一个完成后,第二个应该会自动启动,依此类推。

你能帮我完成这些任务吗?

编辑:

    Option Explicit

    Dim oShell : Set oShell = WScript.CreateObject ("WScript.Shell")
    Dim FSO : set FSO = CreateObject("Scripting.FileSystemObject") 
    Dim Path

    REM oShell.run "ParentChildLinkFinal.vbs", 1, True
    REM oShell.run "Parent_Child_Merge_final.vbs", 1, True
    REM oShell.run "Baddata.vbs", 1, True
    REM oShell.run "CycleTime.vbs", 1, True
    msgBox(oShell.CurrentDirectory)
    MsgBox(FSO.GetFile(Wscript.ScriptFullName).ParentFolder )
    Path=FSO.GetFile(Wscript.ScriptFullName).ParentFolder

    oShell.run Path\ParentChildLinkFinal.vbs, 1, True
    oShell.run Path\Parent_Child_Merge_final.vbs, 1, True
    oShell.run Path\Baddata.vbs, 1, True
    oShell.run Path\CycleTime.vbs, 1, True

我收到以下错误:

变量未定义:“arentChildLinkFinal.vbs”

有什么办法解决这个问题?

【问题讨论】:

  • 对于您编辑的部分,您需要在名称周围加上引号,例如“Path\ParentChildLinkFinal.vbs”。抱歉,我看到路径是一个变量。使用第二个示例检查我更新的答案,然后您不需要包含路径,它可以只是“ParentChildLinkFinal.vbs”。
  • @PeterJ 你今天为我提供了很好的概念!!我刚刚给了你+1。而且我认为我的帖子也得到了更多+1 以将此类研究带入StackOverflow

标签: vbscript


【解决方案1】:

假设您想从另一个 VBS 文件启动,如果工作目录与其他脚本相同,则可以使用以下内容,或者包含完整路径:

Dim oShell : Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "A.VBS", 1, True
oShell.run "B.VBS", 1, True
oShell.run "C.VBS", 1, True
oShell.run "D.VBS", 1, True

您也可以展开代码以将当前目录设置为包含脚本的文件夹:

Dim oShell : Set oShell = WScript.CreateObject ("WScript.Shell")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
oShell.CurrentDirectory = FSO.GetFile(Wscript.ScriptFullName).ParentFolder
oShell.run "A.VBS", 1, True
oShell.run "B.VBS", 1, True
oShell.run "C.VBS", 1, True
oShell.run "D.VBS", 1, True

参数的含义及其他信息见这里:

http://technet.microsoft.com/en-us/library/ee156605.aspx

【讨论】:

  • 感谢彼得的帮助! :-)
  • 我可以为这个帖子提供一些帮助吗? stackoverflow.com/questions/13895587/…
  • 是的,没错,虽然我似乎记得默认启动路径可能会因 Windows 版本或启动方式而有所不同,因此如果遇到任何未找到的文件问题,请尝试使用完整路径。我经常从 Windows 任务事件中进行类似的思考,这使您可以将默认路径设置为脚本的位置。
  • 好的!我现在正在启动我的脚本。但是如果在运行时我们可以将文件路径捕获到一个变量中,然后将它添加到 .vbs 文件中,那可能会更好。有可能吗?
  • 你需要的是 oShell.CurrentDirectory,看看这里technet.microsoft.com/en-us/library/ee156586.aspx
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-25
  • 1970-01-01
  • 2017-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-30
相关资源
最近更新 更多