Windows scripts use Windows Script file (. WSF) 2/4

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.