![]() |
Table of Contents |
![]() |
Introduction to Windows Script ComponentsTo properly introduce WSC, I need to dive a bit deeper into developer-speak than I'm accustomed to doing; so bear with me. First, you should realize that you're already using programming objects in your scripts. Specifically, you're using objects-or components-written to Microsoft's Component Object Model, or COM. I briefly touched on COM in Chapter 5, but here's a quick refresher on what it does for you. When you create, or instantiate, a COM class in a script, you do so by using the CreateObject statement. For example, CreateObject("Scripting.FileSystemObject") creates a new FileSystemObject. When VBScript executes that command, it asks COM to load "Scripting.FileSystemObject" into memory and make it available to VBScript. COM looks up the class "Scripting.FileSystemObject" in the registry. You can open the registry yourself, using Regedit or another editor, and search for "Scripting.FileSystemObject." You'll find that it has a globally unique identifier (GUID) of "{0D43FE01-F093-11CF-8940-00A0C9054228}" and that it's in-process server (InprocServer32) is C:\Windows\System32\scrrun.dll, which is the Microsoft Scripting Runtime DLL. COM loads that DLL into memory when you ask for a FileSystemObject. All COM components must have an in-process server. When you create a new WSC, you're essentially creating a script that pretends to be a COM component. That pretense is helped by Scrobj.dll, which is the WSC in-process server. You can create instances of WSCs within scripts, and when you do so, COM loads Scrobj.dll, which in turn loads the actual WSC script and executes it. So a WSC is a regular VBScript masquerading as a DLL! In fact, any programming language that uses DLLs-including Visual Basic, Delphi, VBScript, C++, and more-can use a WSC, because WSCs meet all of the requirements for regular COM components. Okay, that's enough developer-ese for one chapter. It's time to start looking at how you create these things.
|
![]() |
Table of Contents |
![]() |