To simplify script writing, you can divide a script into multiple parts. Using this method, A. WSF file is created and used as the starting point for execution. Other parts can be. js or. vbs files. These files will be referenced from the. WSF file.
This method causes yourCodeIt is more robust because it isolates each part of the code and allows you to debug one part at a time. It also enables reuse of your code because it allows you to create functions that can be called repeatedly.
Windows Script File (*. WSF) is a text document containing Extensible Markup Language (XML) code.
. WSFFile support |
Implementation |
Include statement |
Merge functions from VBSCRIPT or JScript files to the Windows Script Host project. <Job id = "includeexample"> <Script language = "jscript" src = "FSO. js"/> <Script language = "VBScript"> 'Obtain the available space for drive C. S = getfreespace ("C :") Wscript. Echo s <Sscript> </Job> |
multi-engine |
each file uses Multiple scripting languages.
|
Type Library |
Add constants to the code. <Job id = "includeexample"> <Reference object = "mycomponent. myclass"> <Script language = "VBScript"> Dim myvar Set myvar = Createobject ("mycomponent. myclass ") Currentreturn = myvar. mymethod If currentreturn = false then Wscript. Echo myerror End if </SCRIPT> </Job> |
Tools |
Use any XML editor to edit files. |
Multiple jobs in a file |
Store all the code in one location. In this example, "myfirstjob" is the name of the job contained in the myscripts. WSF file. Cscript // job: myfirstjob myscripts. WSF |
File structure
<? XML version = "1.0"?> < Package > < Comment > Demo wsh </ Comment > < Job ID = "Ie" > <? Job error = "true" DEBUG = "true"?> < Runtime > < Description > ** </ Description > < Named Name = "Ip" Helpstring = "Local or remote IP" Type = "String" Required = "True" /> < Named Name = "U" Helpstring = "User Name" Type = "String" /> < Example > </ Example > </ Runtime > < Script Language = "VBScript" > < ! [CDATA [? -] > </ Script > </ Job > < Job ID = "Office" > ? - </ Job > </ Package >
Basically, the file structure is similar to the above. For details, refer to the "Microsoft Windows Script technology. chm" document or the msdn
MS-help: // Ms. VSCC. v90/ms. msdnqtr. v90.chs/script56/html/vtorimicrosoftwindowsscriptpolicies.htm
.
File Association and execution
Select a. wsffile and click the right button to check that wscript.exeis associated with the file. When this is the case, wscript.exe is used to execute the. WSF file.
If you manually control the execution, there are two forms:
Gui format: wscript.exe demo. WSF
Console format: cscript.exe demo. WSF
[The current path is the root path of demo. WSF]
You can run cscript on the command line to view the execution parameters. Common Commands include:
// Job: XXX: execute a job
// X: Tracking
Tracking debugging
Take demo. WSF as an example, execute the following command line
Cscript.exe demo. WSF // job: jsoffice // X
In this case, you can log on to the script debugger, vs2008, and other development tools for tracking. The initial position is in the first line, and then you can set breakpoints, view variables, and so on.