The below code is a small section of a larger script I am trying to get to run within HouseBot. This sample and its larger brother run just fine outside of HB. Running it inside of HB produces an "Object required: 'WScript'". I have tried different things, but cannot get it to run in HB. What needs to be done to get this to run in HB??
Dim g_objEncoder
Set g_objEncoder = CreateObject("WMEncEng.WMEncoder")
call WScript.ConnectObject(g_objEncoder, "Encoder_")
msgbox "something"
set g_objEncoder = nothing
What do you mean running 'outside of HouseBot'? VBScripts have to run in some environment and I don't think you mean DOS. My first guess would be that you are using WScript and that object is not know inside the HouseBot environment
I mean just what I said, "outside of HouseBot". When I double click on the .vbs file in Windows Explorer it runs just file. So, I am guessing that Windows Explorer is 'setting-up' the environment so that the script will run. The quote below is from the VBScript help:
The WScript object is the root object of the Windows Script Host object model hierarchy. It never needs to be instantiated before invoking its properties and methods, and it is always available from any script file.
To me this means that the WScript object should just be there and not need to be defined. So, the question could become what does HB do to run scripts.
I am going to guess that since houseBot is an exe and it is running inside that exe the WScript has to be one of the linked libraries when HB is compiled otherwise the instantiation is outside the HouseBot environment and housebot cannot find the instantiated methods.
Well, with a lot of digging, I found out that the wscript obj is not available in all VBScript environments. HB must be one of these. From what I found, that is just the way it is. I am thinking that HB(Scott) has no control over it.
The script I am working on, works 'fine' without the "WScript.ConnectObject" line. Only problem is that the events that line defines into the script, control the ending of the script. I am now onto trying to figure out how to define the events in the script without the WScript environment. All the docs out there use the ConnectObject. Wish me luck....
Jumping is easy, it's helping with this issue that is hard.
Scott J,
It looks like you've uncovered the issue that the WScript object is not available to all VBScript code. It's not actually a part of the Active Script Engine that is used by the Script Device, but is provided by the WSH command line tool, which is why it works when being started from the command prompt (or via the Explorer). There's not really anything I can do to add the support.
Did anyone ever come up with a clever workaround for this issue. I have a need to run a remote command-line application when certain properties in HouseBot change values but I ran up against this issue.
Option Explicit
On Error Resume Next
Dim objShell
Dim objExec
Dim objStdOut
Dim objRE
Dim strContent
Dim Status
Dim EnergieBeheer
Set objShell = CreateObject ("WScript.Shell")
Set objExec = objShell.Exec ("powercfg.exe /Q")
Set objStdOut = objExec.StdOut
strContent = objStdOut.ReadAll
Set objRE = New RegExp
objRE.Pattern = ("Minimaal energieverbruik")
objEE.IgnoreCase = True
If objRE.Test(strContent) = True Then
Status = "On"
Else
Status = "Off"
End If
SetPropertyValue "CNQ Status Script.Cool And Quiet", Status
Set objRE = Nothing
Set objStdOut = Nothing
Set objExec = Nothing
Set objShell = Nothing
Pretty standard and it should work if you leave out the WScript part like you suggested. Just test it and it will work. At least my code examples work fine and they run in scripts executed by HB.