arun_roy
arun_roy

Reputation: 601

Calling .VBS files automatically

I have 4 .vbs files, say, A.VbS,B.VBS,C.VBS,D.VBS. I want to call them in the below order:

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

When the first one is done, the second one should start automatically, and so on.

Can you help me to do such tasks?

EDIT:

    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

I get the following error:

Variable is undefined : "arentChildLinkFinal.vbs"

What is the fix for this?

Upvotes: 1

Views: 1384

Answers (1)

PeterJ
PeterJ

Reputation: 3795

Assuming you want to launch from another VBS file you can use the following if the working directory is the same as the other scripts, or otherwise include the full path:

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

As an alternative you can also expand the code to set the current directory to the folder that contains the script:

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

For the meaning of the parameters and other information see here:

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

Upvotes: 2

Related Questions