Running a .vbs script from within a .vbs script 
Author Message
 Running a .vbs script from within a .vbs script

Could someone please help me!! I am trying to run a .vbs
cript from within another script and the script doesn't
seem to recognise it.  I have tried ws.run and call but
neither work... Please could someone help me out on this
one

Thanks in advance

Simon



Mon, 08 Nov 2004 17:58:29 GMT  
 Running a .vbs script from within a .vbs script

Quote:

> Could someone please help me!! I am trying to run a .vbs
> cript from within another script and the script doesn't
> seem to recognise it.  I have tried ws.run and call but
> neither work... Please could someone help me out on this
> one

Post your code, it is easier to help then :)

Anyway, it should work to call another VBScript using the Run method. The
downside is that they cannot share code and variables (variables can of course
be "transferred" using command line parameters or saving then in registry/in a
file).

If you want to share code and variables, there are several ways of doing this.
The different methods all have their pros and cons. Here is a quick overview:

1) Read the second script into a textstream and run ExecuteGlobal or  Execute on
it.

Pros:
Can share all variables, functions and subs.
Easy to implement.

Cons:
If you have an error in the included script, you will not get the line number
where the error arised

2) Use a Windows Script Host File (.WSF) file and include scripts with script
tag.

Pros:
Can share all variables, functions and subs.
Easy to run both VBScript and JavaScript code together.
If you have an error in a included script, you will get the line number where
the error arised.
Easy to implement.

3) Use a Windows Script Component (.WSC).

Pros
You will get a COM interface to your script library (that also can be used by
other programs)
Method/property drop down list and syntax help in editors that supports typelibs

Ideal for development environment with more than one developer

Cons
The most "complicated" solution

***********************************************************

Here are some more details for each method:

___________________________________________________________

1) Read the second script into a textstream and run ExecuteGlobal or Execute on
it.

Load the 2. script into the 1. script at runtime (on the fly) and execute it
with ExecuteGlobal. They can then also share variables, functions etc. The sub
below does this loading:

Sub Include(sInstFile)
    Dim oFSO, f, s
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set f = oFSO.OpenTextFile(sInstFile)
    s = f.ReadAll
    f.Close
    ExecuteGlobal s
End Sub
___________________________________________________________

2) Use a Windows Script Host File (.WSF) file and include scripts with script
tag.

Using Windows Script Files (.wsf)
http://msdn.microsoft.com/library/en-us/script56/html/wsAdvantagesOfW...

An example:
<?xml version="1.0" ?>
<package>
<job>
' this will run "file1.vbs"
<script language="VBScript" src="file1.vbs" />
' this will run "file2.vbs"
<script language="VBScript" src="file2.vbs" />
<script language="VBScript">
'
' Some script code here if you want ...
'
' You can use variables, subs and functions
' from the included files.
'
</script>
</job>
</package>
___________________________________________________________

3) Use a Windows Script Component (.WSC).

Use a Windows Script Component (.WSC) to get a COM interface for your VBSscript
"library".

You can eg. use Windows Script Component Wizard to create
one. Take a look here for more info:
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?co...

Also, using an editor like PrimalScript (http://www.primalscript.com/ ) it is
easy to create/maintain a .wsc file (and you will get drop down list and syntax
help on the fly on your .WSC components from this editor editor if you create a
typelib from your .WSC file)
___________________________________________________________

You can also take a look at this newsgroup thread, it has a discussion about
this:


Subject: Call a subroutine located in another .vbs file
Newsgroups: microsoft.public.scripting.vbscript
Date: 2000/04/27

You can use http://groups.google.com/advanced_group_search to fetch it :-)

--
torgeir



Mon, 08 Nov 2004 18:23:31 GMT  
 Running a .vbs script from within a .vbs script
SJ,

In your .Run method call, add wscript before the script
name like shown below.

Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.Run "wscript c:\Test.vbs", , True

Hope this helps.

Quote:
>-----Original Message-----

>> Could someone please help me!! I am trying to run a .vbs
>> cript from within another script and the script doesn't
>> seem to recognise it.  I have tried ws.run and call but
>> neither work... Please could someone help me out on this
>> one

>Post your code, it is easier to help then :)

>Anyway, it should work to call another VBScript using the
Run method. The
>downside is that they cannot share code and variables

(variables can of course
Quote:
>be "transferred" using command line parameters or saving

then in registry/in a
Quote:
>file).

>If you want to share code and variables, there are

several ways of doing this.
Quote:
>The different methods all have their pros and cons. Here

is a quick overview:
Quote:

>1) Read the second script into a textstream and run

ExecuteGlobal or  Execute on
Quote:
>it.

>Pros:
>Can share all variables, functions and subs.
>Easy to implement.

>Cons:
>If you have an error in the included script, you will not
get the line number
>where the error arised

>2) Use a Windows Script Host File (.WSF) file and include
scripts with script
>tag.

>Pros:
>Can share all variables, functions and subs.
>Easy to run both VBScript and JavaScript code together.
>If you have an error in a included script, you will get

the line number where
Quote:
>the error arised.
>Easy to implement.

>3) Use a Windows Script Component (.WSC).

>Pros
>You will get a COM interface to your script library (that
also can be used by
>other programs)
>Method/property drop down list and syntax help in editors

that supports typelibs

- Show quoted text -

Quote:

>Ideal for development environment with more than one
developer

>Cons
>The most "complicated" solution

>**********************************************************
*

>Here are some more details for each method:

>__________________________________________________________
_

>1) Read the second script into a textstream and run

ExecuteGlobal or Execute on
Quote:
>it.

>Load the 2. script into the 1. script at runtime (on the
fly) and execute it
>with ExecuteGlobal. They can then also share variables,

functions etc. The sub

- Show quoted text -

Quote:
>below does this loading:

>Sub Include(sInstFile)
>    Dim oFSO, f, s
>    Set oFSO = CreateObject("Scripting.FileSystemObject")
>    Set f = oFSO.OpenTextFile(sInstFile)
>    s = f.ReadAll
>    f.Close
>    ExecuteGlobal s
>End Sub
>__________________________________________________________
_

>2) Use a Windows Script Host File (.WSF) file and include
scripts with script
>tag.

>Using Windows Script Files (.wsf)
>http://msdn.microsoft.com/library/en-

us/script56/html/wsAdvantagesOfWs.asp

- Show quoted text -

Quote:

>An example:
><?xml version="1.0" ?>
><package>
><job>
>' this will run "file1.vbs"
><script language="VBScript" src="file1.vbs" />
>' this will run "file2.vbs"
><script language="VBScript" src="file2.vbs" />
><script language="VBScript">
>'
>' Some script code here if you want ...
>'
>' You can use variables, subs and functions
>' from the included files.
>'
></script>
></job>
></package>
>__________________________________________________________
_

>3) Use a Windows Script Component (.WSC).

>Use a Windows Script Component (.WSC) to get a COM

interface for your VBSscript
Quote:
>"library".

>You can eg. use Windows Script Component Wizard to create
>one. Take a { w D ? 4Eo
>?DOc?
>  look here for more info:
>http://msdn.microsoft.com/library/default.asp?

url=/nhp/Default.asp?contentid=28001169
Quote:

>Also, using an editor like PrimalScript

(http://www.primalscript.com/ ) it is
Quote:
>easy to create/maintain a .wsc file (and you will get

drop down list and syntax
Quote:
>help on the fly on your .WSC components from this editor

editor if you create a
Quote:
>typelib from your .WSC file)
>__________________________________________________________
_

>You can also take a look at this newsgroup thread, it has
a discussion about
>this:


>Subject: Call a subroutine located in another .vbs file
>Newsgroups: microsoft.public.scripting.vbscript
>Date: 2000/04/27

>You can use

http://groups.google.com/advanced_group_search to fetch
it :-)

- Show quoted text -

Quote:

>--
>torgeir

>.



Tue, 09 Nov 2004 20:11:07 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Call a VBA procedure from within VBS script?

2. Newbie question - calling a VBS script from another VBS script

3. Include another VBS script file in a main VBS script

4. Launching 6 .vbs scripts simultaneously from a single script

5. Cannot Start debugging .vbs-Script in MS Script Debugger

6. vbs Timer script to run other script

7. Running a file from a .VBS script

8. Cant Run VBS Scripts

9. Change Current directory from within VBS script?

10. Run an exe from within VBS

11. Run a batch file within a VBS???

12. Running PKZip fails from within VBS through Cscript.exe

 

 
Powered by phpBB® Forum Software