Re: calling common routines from other jobs?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Excellent answer, thank you.

All things considered I'll abandon my goal of having a single file, and go
with your first suggestion.

It strikes me as unfortunate that this is not possible though; given that
WSF is touted as a way of packaging related scripts together.
It seems to be more like: "use WSF to package related scripts, provided
they're not so related that they share code"! :-)

Thanks for your help and advice though...

M



"Justin Piper" <jpiper@xxxxxxxxx> wrote in message
news:op.tlm4iqc1cs3d1w@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Wed, 03 Jan 2007 14:07:52 -0600, Michael Lewis
<news@xxxxxxxxxxxxxxxxxx> wrote:

Can anyone advise me on how to write a WSF file that enables me to define
common functions that are callable from multiple "jobs" within that wsf
file.

The best way would be to put the common functions in a common.vbs file,
and then include the file in each job:

<package>
<job id="Job1">
<script language="vbscript" src="common.vbs"></script>
<script language="VBScript">
Wscript.Echo ReallyUsefulFunction
</script>
</job>
</package>

(I'm keen that the solution does not involve creating other files and
does
not required registration of any COM objects.)

If the trouble of distributing more than one file is the only reason you
are averse to this, I suggest packing everything in a self-extracting
executable. There are some[1] that are intended primarily to protect
script source that would work particularly well.

If creating additional files is absolutely unacceptable, I think you're
stuck. Resources are local to each job, so this won't work:

<package>
<resource id="common">
function ReallyUsefulFunction
ReallyUsefulFunction = "some result"
end function
</resource>

<job id="Job1">
<script language="vbscript">
Execute GetResource("common")
</script>
<script language="VBScript">
Wscript.Echo ReallyUsefulFunction
</script>
</job>
</package>

And even if you were desperate enough to try it, WSF files don't support
doctype definitions:

<?xml version="1.0"?>
<!DOCTYPE wsf [
<!ENTITY common "function
ReallyUsefulFunction:ReallyUsefulFunction=&quot;some result&quot;:end
function">
]>
<package>
<job id="Job1">
<script language="vbscript">
Execute GetResource("&common;")
</script>
<script language="VBScript">
Wscript.Echo ReallyUsefulFunction
</script>
</job>
</package>

You might be able to put the common code in another job, then have each
job spawn a second instance of WSH running the common job and have them
communicate via the IEPipe idiom, but the code for _that_ would probably
be more complex than ReallyUsefulFunction was in the first place.

[1] EnkelAdress Software - vbs2exe
http://www.enkeladress.com/vbs2exe.htm

--
Justin Piper
Bizco Technologies
http://www.bizco.com/


.



Relevant Pages

  • Re: calling common routines from other jobs?
    ... The best way would be to put the common functions in a common.vbs file, and then include the file in each job: ... Wscript.Echo ReallyUsefulFunction ... And even if you were desperate enough to try it, WSF files don't support doctype definitions: ...
    (microsoft.public.scripting.vbscript)
  • Re: calling common routines from other jobs?
    ... Michael, as you are using a "wsf" file, you might consider ... and use execute or executeglobal to run it. ... Wscript.Echo ReallyUsefulFunction ...
    (microsoft.public.scripting.vbscript)