Windows scripting jscript




















The actual data stored for the color might be a character string such as "red" or "green". Tartness might be represented as number from 0 sugary sweet to 10 brings tears to your eyes.

An object describing a file on a hard drive might have properties such as filename a character string and size a number. An object representing a hard drive might have properties describing the hard drive's size, volume name, and also the drive's contents. Now, the contents of a hard drive could be represented as a list of filenames or an array of string values.

However, it might be more useful if the hard drive could yield a list of file objects that you could then use to work with the files themselves. This is actually how many objects work. When appropriate, objects can return references to other objects.

When an object needs to give you several other objects, it will give you a special object called a collection , which holds within it an arbitrary number of other objects. For example, a Folder object might represent a folder on your hard drive, and its Files property might yield a collection of File objects, which represent the files in the folder, as illustrated in Figure 3. The contents of a folder can be represented by collections of File and Folder objects.

A collection object can actually hold any type of object inside it, and the collection object itself has properties and methods that let you extract and work with these objects. This is a common thing to see in object programming: "container" objects that contain other objects, of any arbitrary type. You'll see many examples of collections in later chapters. Windows ActiveX objects use container objects that have two properties: Item and Length.

The Length property indicates how many items are in the collection. The Item property retrieves one of the individual items. For some collections, you can extract individual objects from the Item collection using Item 0 , Item 1 , and so on, but for many collections, the Item property requires a name or other arcane bit of identifying information.

Therefore, each scripting language provides a more general way of letting you examine all the objects in a collection. I'll discuss this in more detail later in the chapter.

Collections are pervasive in Windows script programming, and some languages have special means of working with them. I'll give examples of using collections in each of the scripting languages discussed later in the chapter. Because objects are separate program components, scripts and other programs that use them need a way to locate them and tell Windows to activate them.

In this section, I'll describe how this is done. Each programmer who creates an object class gives it a name that, with any luck, is fairly self-explanatory. For example, Scripting. Each of the programming languages you can use with WSH has a way of creating an object instance given just this name. For example, in VBScript, the statement. In either case, the statement causes the Windows Script Host interpreter to ask Windows to create an instance of the specified object.

Windows looks up the object name in the Registry, finds the name of the program file that manages this object class usually a file whose name ends in. The class program creates an instance of the object and gives your script a reference with which it can use and manipulate the object.

I'll show you how to do this in each WSH-compatible language later in this chapter. For almost all cases, this is all you need. In the remainder of this chapter, I'll tell you how to use objects in VBScript and other languages. The next section on VBScript will follow the tutorial style of Chapter 2, "VBScript Tutorial," whereas the descriptions for other languages will assume more experience with programming.

Finally, at the end of the chapter, I'll tell you how to find useful objects not discussed in the later chapters of this book. I would like to receive exclusive offers and hear about products from InformIT and its family of brands.

I can unsubscribe at any time. Get new features first. Was this information helpful? Yes No. Thank you! Any more feedback? The more you tell us the more we can help. Can you help us improve? Script files are text files. By convention, VBScript files have the extension. To run a script from the command prompt, run the Cscript. You can print out a list of the parameters supported by Cscript.

CreateObject method. Connect and share knowledge within a single location that is structured and easy to search. I have been using JavaScript in Windows Scripting, both in. JS files and. WSF files, for several years, but I have found that there are some methods that are not recognized when I put them in a script that is executed outside a web page that are valid in a script on a web page. I know that different browsers support different versions of JavaScript, and MSDN has a page that describes which functions and methods are supported in which Internet Explorer and Edge browser versions:.

Does the version of JavaScript supported in Windows Scripting depend on the version of Windows, the version of Internet Explorer installed on the computer, or some other factor or combination of factors?

Is there a way inside the JavaScript program to detect which version of JavaScript is being used as it is executed? In fact, it can support a number of scripting implementations through its support for Active Scripting languages. While it shares many similarities with JavaScript, they are not the same yes, they came from the same place, but that doesn't mean they didn't diverge afterwards. When you use. This also applies when using.

Edit: I've also updated the wsh tag info as it states javascript can be used, which is incorrect and why so much confusion arises around this topic. At this time all the above features was the gonna be the next big thing in EcmaScript 6. CreateObject "". How are we doing? Please help us improve Stack Overflow. Take our short survey.



0コメント

  • 1000 / 1000