Include File in VBS 
Author Message
 Include File in VBS

I decided to write my batchs in VBS.

Which is the command to include a file in a vbs-script ?

I try this :
<!-- #include file="myFile.inc" -->

Thanks for any help,

J.Curvale



Tue, 26 Apr 2005 17:54:37 GMT  
 Include File in VBS
Jr?me,

Do you mean you are writing a .vbs file and want to include external
functions/procedures as executable code?

This can be done two ways.

(1) Use a WSF.

WSF files are discussed in the documentation; they are basically any Windows
scripts "wrapped" in XML, but have all sorts of neat extra abilities.  You can
get the docs in French here:

http://download.microsoft.com/download/winscript56/install/5.6/w98nt4...

A WSF file can include external files with a simple declaration.

For example, let's say you save a VBScript subroutine in a text file.  You can
write a WSF that loads it and then uses the functions.

Example VBScript code in a file:
'c:\tmp\sub.txt
Sub Hello
 MsgBox "Hello, World!"
End Sub

The following WSF file would then load that file and can call the Hello
procedure, like this:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- helloworld.wsf -->
<package>
<job>
<script language="VBScript" src="c:\tmp\sub.txt"/>
<script language="VBScript">
<![CDATA[
 Hello
 ]]>
</script>
</job>
</package>

(2) Write an include function that uses ExecuteGlobal.

You can load text from a file using FSO, then execute the included code using
VBScript's native "Execute" or "ExecuteGlobal" commands.  Here is a variation on
the above.  This is a pure .vbs file that has an "include" subroutine to load
code from the same text file as above, execute it so it is loaded in the script
engine, then call it.

'helloworld.vbs
Include "c:\tmp\sub.txt"

Hello

Sub Include(FilePath)
 ' Given the path to a file, will execute entire contents
 ' in global context
 Const ForReading = 1, TristateUseDefault = -2, _
  DoNotCreateFile = False
 With CreateObject("Scripting.FileSystemObject")._
  OpenTextFile(FilePath, ForReading, _
  False, TristateUseDefault)
  ExecuteGlobal .ReadAll: .Close
 End With
End Sub

--
Please respond in the newsgroup so everyone may benefit.
 http://dev.remotenetworktechnology.com
 ----------
 Subscribe to Microsoft's Security Bulletins:
 http://www.microsoft.com/technet/security/bulletin/notify.asp


Quote:
> I decided to write my batchs in VBS.

> Which is the command to include a file in a vbs-script ?

> I try this :
> <!-- #include file="myFile.inc" -->

> Thanks for any help,

> J.Curvale



Tue, 26 Apr 2005 18:25:10 GMT  
 Include File in VBS

Quote:
> Do you mean you are writing a .vbs file and want to include external
> functions/procedures as executable code?

> This can be done two ways.

> (1) Use a WSF.
> (snip)

> (2) Write an include function that uses ExecuteGlobal.
> (snip)

and for a pros/cons listing between the two methods:


Subject: Re: Calling one script from another.
Newsgroups: microsoft.public.scripting.wsh
Date: 2002-09-09 11:00:35 PST
http://groups.google.com/groups?selm=3D7CD272.614629F7%40hydro.com

--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway



Wed, 27 Apr 2005 01:38:17 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. INCLUDE file in .VBS file?

2. include files in vbs

3. including files in VBS

4. include file with VBS ?

5. how to add a include file with .vbs script ?

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

7. include files and/or parameters betw vbs-files

8. ASP 2 VBS, include file problme

9. How to include vbs files

10. vbs include files

11. How I include vbs files ?

12. How to include other VBS files

 

 
Powered by phpBB® Forum Software