0

I have a vbscript file A that will call another vbscript file B. File B requires arguments and it is located in the same folder with file A.

The code works like this:

  1. File A.vbs is located in C:\temp

  2. In File A, call C:\temp\B.vbs

Wherever folder I put these vbs files, as long as they are on the same folder, file A should call file B without changing the code. How can I do this in VBScript?

rajeemcariazo
  • 2,476
  • 5
  • 36
  • 62
  • possible duplicate of [Run a vbscript from another vbscript](http://stackoverflow.com/questions/1686454/run-a-vbscript-from-another-vbscript) – Helen Jan 20 '11 at 09:33
  • You'd put a comment under my answer that the relative path didn't work, so I added an alternative solution, though that comment has been deleted now, but I'll leave the alternative one in just in case. – Hans Olsson Jan 20 '11 at 10:12

2 Answers2

0

I'm not sure what the question is but it sounds like you're wondering how you know what path to use. If so, I think that it should just work with a relative path like .\B.vbs.

Otherwise if the question is how do you execute one script from another, look at Shell.Run.

So all put together, something like WshShell.Run ".\B.vbs arg1 arg2" should work I think.

Edit: If the relative path doesn't work, just use WScript.ScriptFullName to get the path of the currently executing script as:

WshShell.Run Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "B.vbs arg1 arg2"
Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
0

Try this:

Dim aShell
Set aShell = CreateObject ("WScript.Shell")
aShell.Run "B.vbs"
Set aShell = Nothing
cigien
  • 57,834
  • 11
  • 73
  • 112