Introducing Custom Objects with WSC
(Page 1 of 4 )
If you’ve been scripting for more than a few minutes, you’ve undoubtedly used some form of COM object in your scripts. These are objects provided by the operating system and other applications that allow you to perform tasks that aren’t provided by the scripting environment. Most of these objects are compile code that resides in a DLL or OCX file somewhere. Most people believe that you have to have some level of advanced programming ability to create these objects for yourself. That’s not the case. Today I’m going to show you how to create custom COM objects using nothing more than the scripting knowledge you already possess.
The technology we’ll be using is called Windows Script Components—a technology designed specifically to allow programmers to create objects with nothing more than a knowledge of scripting. The Windows Script Component Technology works with the scripting environment to expose simple scripts as COM-enabled objects.
The WSC technology was originally known as Scriplets, a means of creating small COM-enabled applications and objects for use in web development. However, since this technology relies on COM, this isn’t just limited to browser-based development. It can be utilized by any technology that is capable of working with a COM interface. As COM gained more and more popularity (and Windows Scripting became more widely used), the Scriptlet technology was expanded into Windows Script Components.
Creating a Windows Script Component is as easy as creating a text file. At its most basic level, a WSC is little more than a Windows script wrapped inside of an XML file. This XML file is used to provide the information necessary for the component to be recognized as a COM object, while the contained script performs the programming magic.
A WSC is powered by the Windows Script Host environment. The WSC is (generally) registered on the system as a COM object. When that object is instantiated, the system points to the WSC file, which is then executed by the Windows Script Host and exposed to the calling application through a generated COM interface. This is all done seamlessly behind the scenes so that the result is no different from what would have happened if the programmer had used some compiled object.
Next: Advantages of using custom COM objects >>
More Code Examples Articles
More By Nilpo