Calling all scripts.... 
Author Message
 Calling all scripts....

There is probably a very obvious answer to this question but being new to
vbs and the scripting host I need a little guidance.  I am working with a
third party application that utilizes the windows scripting host for
extending and customizing native application behavior.  The parent
application exposes certain events and provides an administration tool for
allowing the application administrator to associate .vbs files with these
events.  The problem is I need to dynamically run any of a number of
different scripts when a single event occurs.  So, I would like to create a
hierarchy of scripts and associated the highest level (main) script with an
application event.  Now for my question... How do I actually call the
related scripts from the main script when each script is in a separate .vbs
file?

Thanks in advance,

chris



Tue, 22 Jul 2003 18:46:21 GMT  
 Calling all scripts....

Quote:

> There is probably a very obvious answer to this question but being
> new to vbs and the scripting host I need a little guidance.  I am
> working with a third party application that utilizes the windows
> scripting host for extending and customizing native application
> behavior.  The parent application exposes certain events and provides
> an administration tool for allowing the application administrator to
> associate .vbs files with these events.  The problem is I need to
> dynamically run any of a number of different scripts when a single
> event occurs.  So, I would like to create a hierarchy of scripts and
> associated the highest level (main) script with an application event.
>  Now for my question... How do I actually call the related scripts
> from the main script when each script is in a separate .vbs file?

> Thanks in advance,

> chris

One of two ways, using WSHShell.Run method or by making your 'main'
routine a *.wsf file and 'including' your other scripts into it.

The Run method would look something like this ...

  ScriptFileName = "d:\somepath\scriptname.vbs"
  set oWS = CreateObject("Wscript.Shell")
  oWS.Run Wscript.FullName & " " & ScriptFileName, 1 , True

For more information on the syntax, see the WSH documentation.

The WSF file usage is best researched in the documentation.  See
'include' or '.wsf' in the Index.

Documentation (compiled html version for download) ...

  http://msdn.microsoft.com/scripting/windowshost/wshdoc.exe

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Tue, 22 Jul 2003 21:41:12 GMT  
 Calling all scripts....
The application is actually utilizing the VBScript ActiveX script engine, not the windows scripting
host.  They are doing this by directly hosting the script engine (just like wscript.exe does) or
they may even be using the MS Script Control.

If you need to execute several scripts in response to a given event, then how you would do that
depends on what each script needs to see when it executes.  By that I mean whether or not it needs
to be able to access the object model of the host application.

You'll need a "driver" script that is linked to the event that in turn executes the additional
scripts.  How you execute them depends on their need (or lack thereof) to access the host's object
model.

---> If no host object access is needed then use the WshShell.Run technique that has already been
suggested.

---> If host object access is needed, then you have a couple of choices.

One is to read the "child" scripts (to be executed) as a text files and then use Execute or
ExecuteGlobal to actually execute the text as code.  This executes the code in the same namespace as
the "driver" script, so the code will have access to the same host objects that the driver does.
The downside to this technique is that all of the dynamically executed code executes in the same
namespace as the "driver" which presents the possibility of namespace conflicts (names of variables,
procedures, etc.).  If the child scripts are carefully written, then that isn't a big issue.

The second method that avoids the namespace conflict problem is to write the child scripts as WSCs
(Windows Script Components).  The driver would create instances of the WSCs and pass references to
the host object model as needed.  The code within the WSC is a separate namespace so there is no
potential for namespace conflicts.

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> There is probably a very obvious answer to this question but being new to
> vbs and the scripting host I need a little guidance.  I am working with a
> third party application that utilizes the windows scripting host for
> extending and customizing native application behavior.  The parent
> application exposes certain events and provides an administration tool for
> allowing the application administrator to associate .vbs files with these
> events.  The problem is I need to dynamically run any of a number of
> different scripts when a single event occurs.  So, I would like to create a
> hierarchy of scripts and associated the highest level (main) script with an
> application event.  Now for my question... How do I actually call the
> related scripts from the main script when each script is in a separate .vbs
> file?

> Thanks in advance,

> chris



Wed, 23 Jul 2003 01:33:55 GMT  
 Calling all scripts....
Michael,

Thank you for your post... The scripts will need access to objects that are
exposed by the host application (just as you anticipated).  The vendor has
indicated that registering all scripts with the host application even though
the main script is the only one tied to an event will make the child scripts
"available" to be called by main script.  I have attempted to simply call
the child script as you would any local procedure or function - with no
success (Main script exectes but does not execute the child script).  I will
explore your WSC suggestion as it seems to most closely resemble what I am
trying to do.
Assuming my vendor is not lying to me about the script registration and
script calling convention; any thoughts regarding the syntax for actually
calling a child procedure from another script (see code sample below)?

=[.vbs file 1]=================
'
' Main.vbs script - associated with host application event.
'
Sub Main()
    Call ChildProc()        ' Syntax in question for calling an external
procedure?
End Sub
'(eof)

=[.vbs file 2]=================
'
' ChildProc.vbs - only registered with host application.
'
Sub ChildProc()            ' the external procedure
    ' Do something...
End Sub
'(eof)

Thanks in advance... chris


Quote:
> The application is actually utilizing the VBScript ActiveX script engine,

not the windows scripting
Quote:
> host.  They are doing this by directly hosting the script engine (just

like wscript.exe does) or
Quote:
> they may even be using the MS Script Control.

> If you need to execute several scripts in response to a given event, then

how you would do that
Quote:
> depends on what each script needs to see when it executes.  By that I mean

whether or not it needs
Quote:
> to be able to access the object model of the host application.

> You'll need a "driver" script that is linked to the event that in turn

executes the additional
Quote:
> scripts.  How you execute them depends on their need (or lack thereof) to

access the host's object
Quote:
> model.

> ---> If no host object access is needed then use the WshShell.Run

technique that has already been
Quote:
> suggested.

> ---> If host object access is needed, then you have a couple of choices.

> One is to read the "child" scripts (to be executed) as a text files and
then use Execute or
> ExecuteGlobal to actually execute the text as code.  This executes the

code in the same namespace as
Quote:
> the "driver" script, so the code will have access to the same host objects

that the driver does.
Quote:
> The downside to this technique is that all of the dynamically executed

code executes in the same
Quote:
> namespace as the "driver" which presents the possibility of namespace

conflicts (names of variables,
Quote:
> procedures, etc.).  If the child scripts are carefully written, then that
isn't a big issue.

> The second method that avoids the namespace conflict problem is to write

the child scripts as WSCs
Quote:
> (Windows Script Components).  The driver would create instances of the

WSCs and pass references to
Quote:
> the host object model as needed.  The code within the WSC is a separate

namespace so there is no
Quote:
> potential for namespace conflicts.

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --

> Please do not email questions - post them to the newsgroup instead.
> --



> > There is probably a very obvious answer to this question but being new
to
> > vbs and the scripting host I need a little guidance.  I am working with
a
> > third party application that utilizes the windows scripting host for
> > extending and customizing native application behavior.  The parent
> > application exposes certain events and provides an administration tool
for
> > allowing the application administrator to associate .vbs files with
these
> > events.  The problem is I need to dynamically run any of a number of
> > different scripts when a single event occurs.  So, I would like to
create a
> > hierarchy of scripts and associated the highest level (main) script with
an
> > application event.  Now for my question... How do I actually call the
> > related scripts from the main script when each script is in a separate
.vbs
> > file?

> > Thanks in advance,

> > chris



Wed, 23 Jul 2003 16:47:09 GMT  
 Calling all scripts....

Quote:
> Assuming my vendor is not lying to me about the script registration and
> script calling convention; any thoughts regarding the syntax for actually
> calling a child procedure from another script (see code sample below)?

> =[.vbs file 1]=================
> '
> ' Main.vbs script - associated with host application event.
> '
> Sub Main()
>     Call ChildProc()        ' Syntax in question for calling an external
> procedure?
> End Sub
> '(eof)

> =[.vbs file 2]=================
> '
> ' ChildProc.vbs - only registered with host application.
> '
> Sub ChildProc()            ' the external procedure
>     ' Do something...
> End Sub
> '(eof)

Looks logical enough, but...

I'm going to guess that you probably need to call the Functions or Subs in other "registered"
scripts as methods of a host provided object or objects.  When you "register" a script with the
application, do you need to assign it a unique name?  How do you "associate" a registered script
with an event?  By file name or via a registered name?  Is there a required convention for naming
the entry points into registered scripts associated with an application event?  ...???

Note that these are all rhetorical question...  Without knowing what the application (or who the
vendor) is and therefore not having access to any documentation (assuming they provide anything
useful ;-) this is only a guess on my part...

At least, if I were going to architect an application like this, I would do something similar.  In
fact, I would probably just use the MS Script Control and its Modules collection and the CodeObject
property of a Module....

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--



Thu, 24 Jul 2003 03:59:13 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Calling server-script from within client-script

2. calling a script from within a script?

3. Call a script from another script

4. Calling server-script from within client-script

5. How to call a script within a script

6. Calling ServerSite Script from ClientSide Script

7. Calling a script from within a script....

8. Calling a script from within a script....

9. Can one script call another script?

10. Call another script within a script

11. How can I call another Script

12. Loading or calling client scripts from the server...

 

 
Powered by phpBB® Forum Software