Windows Script Components

Share your scripts written for the Script Device in this forum.
Post Reply
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Windows Script Components

Post by Osler »

I think we have all encountered scripts that will crash or hang HouseBot. From my experience, the issue is typically when using a CreateObject call to a specific DLL from within the HouseBot scripting engine....at least this was the case for me when working with the UPnP.dll from Microsoft. Though the typical course would have been to make an ActiveX DLL in Visual Studio, this didn't work either due to issues between VB6 and the DLL. I believe I have found a solution/work-around that anyone proficient with VBScript can use: windows script components. Once created, a component can be registered just like a DLL and called from within a script using the same syntax (Set Foo = CreateObject("Foo.Bar")). It seems that the components are instantiated outside of the HouseBot scripting engine and, thus, are not prone to the calling issues inherent to the HouseBot environment. Properties, Functions, and Events can be set just as if you were creating a Class Object. I have successfully used the UPnP.dll from within HouseBot by using a windows scripting component. This may obviate the need to use the ExecuteProgram Device with cscript/wscript to run certain scripts. By keeping things within HouseBot, it is no longer necessary to use External Control and the limitation on size for list population is minimized.

A primer on WSC can be found here:

http://www.4guysfromrolla.com/webtech/050400-1.shtml

The Windows Script Component Wizard can be found here:

http://www.microsoft.com/downloads/deta ... laylang=en

This should allow for easy creation of "code modules" for use in HouseBot with the benefit of increasing the reliability of scripts run within HouseBot.

Osler
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Post by Richard Naninck »

Unexplained errors occur when usings objects if the object is re-used and not set to Nothing before re-using it.

I had this with my email script. I could run an email check about 90 times and then it would hang HB. After debugging I found a loop in which the object was not reset to Nothing. After adding 'Set myObject = Nothing', no more hangs occured. I have seen this on many occasions in scripts written by different people. Always the same thing... HB would hang without some coding explanation. Maybe this is the case in your scripts as well....
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Post by Osler »

No...it chokes on the actual CreateObject call. If you try this code:

Code: Select all

Dim Finder
Dim Device

Set Finder = CreateObject("UPnP.UPnPDeviceFinder")

Set Device = Finder.FindByType("blablabla")

Set Device = Nothing

Set Finder = Nothing
This will choke HB.

Osler
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Post by Osler »

Hmmm...you may be correct on this. I was at least able to use the UPnP.dll from within HB to perform a FindByUDN and FindByType. My initial failed attempts may have been due to "poor coding practices".

Well, at least all of the functionality of the sonos system are now encapsulated in an easy to use COM object.....and I had fun doing it!!!

Osler
Post Reply