Coding a Custom Object with WSC - Registering and using your component
(Page 4 of 5 )
With all of the pieces in place, you’re ready to put your new component to the test. Make sure that you save the latest changes and move it to a directory where you can leave it. Once a component is registered, it cannot be moved, because the system is going to save its location.
You should be able to register and unregister your component very easily using the context menu entry in My Computer. Navigate to the directory where you put it, right-click on the WSC file, and choose Register. If you don’t have an option to register it, you can do it from the command line as follows.
regsvr32 “C:pathtoZipFolder.wsc”
Once your component has been registered, it is immediately available to the system. You can write a script now that implements your object by instantiating it by its Prog ID.
Set objZipFolder = CreateObject("ZipFolder.WSC")
One of the beauties of using WSCs over compiled code is that now, even though it’s already registered, you can still open the file and make changes without having to unregister and re-register the component. Changes will take effect immediately!
While you really should always register your components, let’s assume for some reason that you don’t want to. Maybe you're in a really restricted environment or only intend to use your component a couple of times. In any case, there is one little-known method for instantiating a Windows Script Component without having to register it on the host system.
Set objZipFile = GetObject("script:C:componentsZipFolder.wsc")
You can use the GetObject method to instantiate your script component directly. The magic is the use of the script: protocol. You will need to provide the full path to the WSC file. But that’s not all…
Set objZipFile = GetObject("script:ServercomponentsZipFolder.wsc")
…it can be any valid file path—including network paths…
Set objZipFile = GetObject("script:http://www.example.com/pub/ZipFolder.wsc")
…and even web locations!
Next: Protecting your intellectual property >>
More Code Examples Articles
More By Nilpo