1

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?

2
  • 1
    For your edited part you need to put quotes around the name, such as "Path\ParentChildLinkFinal.vbs". Sorry, I see path is a variable. Check my updated answer with the second example then you won't need to include the path, and it can just be "ParentChildLinkFinal.vbs". Commented Dec 26, 2012 at 6:49
  • @PeterJ Excellent concept you have provided me today!! I just gave you +1. And I think My post also get some more +1 to bring such research in StackOverflow Commented Dec 26, 2012 at 6:52

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

8 Comments

May I have some help for the post? stackoverflow.com/questions/13895587/…
Yes that's right, although I seem to recall the default start path can vary a bit either by Windows versions or how it's launched, so if you run into any file not found problems try using the full path. I often do similar thinks from a Windows task event, and that lets you set the default path to the location of the script.
Okay! I am now starting my scripts.But it could be better if in run time we can catch the file path into a variable and then adding it to the .vbs file. Is it possible?
It's oShell.CurrentDirectory you'll need, take a look here technet.microsoft.com/en-us/library/ee156586.aspx
I am getting an error saying that The system couldn't find the specified path
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.