Windows Script File

Windows Script File

Infobox file format
name = Windows Script File
extension = .wsf
owner = Microsoft
genre = Scripting
container for = Scripts
A Windows Script File (WSF) is a file type used by the Microsoft Windows Script Host. It allows mixing scripting languages such as Perl, Object REXX, Python, Kixtart, JScript, and VBScript within a single file. These types of scripts may also be used to link many other external scripts together using a src parameter on the '** This will work... definitely...

The first script module will produce a "divide by zero" error. Typically this would cause the script to end in the Windows Script Host but this modular method allows the script to continue and execute the second script module.

Exposing constants

Another very useful feature of a WSF is that the XML wrapper can be bound to an object reference or control so you can use that object's constants instead of having to declare them. In regular VBScript and JScript files, you would be forced to declare a constant's value (outside of those that are internal to the Windows Script Host) in order to use the constant. An example of this is shown below:

const adLockBatchOptimistic = 4 MsgBox "The value of ""adLockBatchOptimistic"" is " & _ adLockBatchOptimistic & ".", vbInformation,"adLockBatchOptimistic"

If your object documentation only refers to the constant's name and not the constant's value, you would have no way of knowing the value without the help of an Integrated development environment to tell you what they equate to. By using the WSF reference declaration, you can use the constants without declaring their values. The example below enumerates the values of several common constants in the ADO (ActiveX Data Objects) Recordset.

<?xml version="1.0" ?> <!-- WSF Example with Object Reference Notes for this very formal example: CDATA is used to help the XML parser ignore special characters in the content of the script. --> <package> <job id="EnumerateConstantsADO"> <reference object="ADODB.Recordset" /> <script language="VBScript"> <! [CDATA [ dim title, str, i ctecArray = Array("adOpenUnspecified","adOpenForwardOnly", _ "adOpenKeyset","adOpenDynamic","adOpenStatic") title = "ADO Recordset Values for Constants" str = title & vbNewLine & vbNewLine str = str & "*CursorTypeEnum Constants*" & vbNewLine For i = 0 to ubound(ctecArray) str = str & Eval(ctecArray(i)) & vbTab & ctecArray(i) & vbNewLine Next str = str & vbNewLine str = str & "*LockTypeEnum Constants*" & vbNewLine ltecArray = Array("adLockUnspecified","adLockReadOnly", _ "adLockPessimistic","adLockOptimistic", _ "adLockBatchOptimistic") For i = 0 to ubound(ltecArray) str = str & Eval(ltecArray(i)) & vbTab & ltecArray(i) & vbNewLine Next MsgBox str, vbInformation, Title ] > </script> </job> </package>

Running the above script from a file with a ".WSF" extension, such as one named "EnumerateConstantsADO.wsf", will produce the result shown in the picture at the right of this paragraph. Using the object reference to expose the constants makes writing the script more like writing in a standard programming language. In fact, the contents of the sample script, written in VBScript, will actually compile into a Visual Basic program and run the same way as long as that program uses the same reference to ADODB.

See also

*Windows Script Host
*Shell script
*Windows PowerShell
*Active Scripting
*JScript
*VBScript

External links

* [http://msdn2.microsoft.com/en-us/library/15x4407c.aspx Using Windows Script Files] - From Microsoft's website
* [http://www.microsoft.com/technet/scriptcenter/scripts/language.mspx?mfr=true Scripting Languages Available in the Script Center] - From Microsoft's website


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Windows Script Host — The Icon For Windows Script Host The Microsoft Windows Script Host (WSH) is an automation technology for Microsoft Windows operating systems that provides scripting capabilities comparable to batch files, but with a greater range of supported… …   Wikipedia

  • Windows Script Host — (WSH; первоначально назывался Windows Scripting Host, был переименован ко второму выпуску)  компонент Microsoft Windows, предназначенный для запуска сценариев на скриптовых языках JScript и VBScript, а также и на других дополнительно… …   Википедия

  • Windows PowerShell — Screenshot of a sample PowerShell session …   Wikipedia

  • Windows XP — Windows Experience redirects here. For Windows Experience Index, see Windows System Assessment Tool. Windows XP Part of the Microsoft Windows family …   Wikipedia

  • Windows 2000 — Part of the Microsoft Windows family Screenshot of Windows 2000 Professional …   Wikipedia

  • Windows 98 — Part of the Microsoft Windows family …   Wikipedia

  • Windows PowerShell — Windows PowerShell …   Википедия

  • Windows Template Library — Тип библиотека (программирование) Разработчик Nenad Stefanovic Написана на С++ Операционная система Microsoft Windows Последняя версия WTL 8.1.11324 (21.11.2011) Лицензия …   Википедия

  • Windows Installer — (установщик Windows)  подсистема Microsoft Windows, обеспечивающая установку программ (инсталлятор). Является компонентом Windows, начиная с Windows 2000; может доустанавливаться и на более ранние версии Windows. Вся необходимая для установки… …   Википедия

  • Windows Server 2008 — Datei:Logo Microsoft Windows Server 2008.svg Entwickler Microsoft Version Build 6001 (27. Februar 2008) Abstammung …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”