VBScript to counter LG TV 2 hour automatic turn off

I created the following VBScript, utilising ypid's version of lgcommander.py, to counter the fact that our office display TVs will turn off 2 hours after their preset 08:30 turn on time unless they receive some kind of remote input. This despite the fact that they aren't scheduled to turn off until 18:00.

Just copy the whole lot between the ~~~ lines into a single text file and save it with a .vbs extension. The script can then be launched manually or, as I do, via Windows scheduler. You will also need to have the appropriate version of Python installed (make sure you allow it to write the python path to the registry) and ypid's version of lgcommander.py.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Author Nick Hewett - 14/11/2014
' This VBscipt is designed to send a remote command to multiple LG TVs connected to the same LAN
' It uses this Python script-> https://github.com/ypid/lgcommander

PATH = "C:\Display\"
APP = "python"
SCRPT = "lgcommander.py"

' The next 2 string declarations must have the same number of comma separated elements
' lgHosts lists the IP addresses of your TVs, lgKeys lists the corresponding TV pairing keys
' NB. they must be in the correct order and the IP addresses must be static.

lgHosts = "10.44.18.15, 10.44.18.16, 10.44.18.17, 10.44.18.18, 10.44.18.19, 10.44.18.20"
lgKeys = "158905, 928905, 728905, 398905, 998905, 668905"

' I don't use all of these but they may be useful to you
KEY_IDX_3D=400
KEY_IDX_ARROW_DOWN=2
KEY_IDX_ARROW_LEFT=3
KEY_IDX_ARROW_RIGHT=4
KEY_IDX_ARROW_UP=1
KEY_IDX_BACK=23
KEY_IDX_BLUE=29
KEY_IDX_BTN_1=5
KEY_IDX_BTN_2=6
KEY_IDX_BTN_3=7
KEY_IDX_BTN_4=8
KEY_IDX_CH_DOWN=28
KEY_IDX_CH_UP=27
KEY_IDX_ENTER=20
KEY_IDX_EXIT=412
KEY_IDX_EXTERNAL_INPUT=47
KEY_IDX_GREEN=30
KEY_IDX_HOME=21
KEY_IDX_MUTE=26
KEY_IDX_MYAPPS=417
KEY_IDX_NETCAST=408
KEY_IDX_PAUSE=34
KEY_IDX_PLAY=33
KEY_IDX_POWER_OFF=1
KEY_IDX_PREV_CHANNEL=403
KEY_IDX_RED=31
KEY_IDX_STOP=35
KEY_IDX_VOL_DOWN=25
KEY_IDX_VOL_UP=24
KEY_IDX_YELLOW=32

' Change the next line to suit your purposes, in my case I just want to send an 'ENTER' command 
' to stop the screens turning off 2 hours after an automatic turn on...
CMD = "-c " & KEY_IDX_ENTER

' Change 'roap' to 'hdcp' for pre-2012 TVs or omit Protocol command if unsure...
PROTO = "-P roap"

Call Send_Enter(PATH & SCRPT, CMD)

Sub Send_Enter(ByVal aFile, ByVal aCmd)
Dim oShell
Dim myKey
Dim myHost
Dim arrHosts
Dim arrKeys
Dim Instruction

  arrHosts = Split(lgHosts, ",")
  arrKeys = Split(lgKeys, ",")

  For i = LBound(arrHosts) to UBound(arrHosts)
    myHost = "--host " & Trim(arrHosts(i))
    myKey = "-k " & Trim(arrKeys(i))

    Instruction = APP & " " & aFile & " " & PROTO & " " & aCmd & " " & myHost & " " & myKey

    Set oShell = CreateObject("Wscript.Shell")

   ' Wscript.Echo Instruction

    oShell.Run Instruction
  Next

  Set oShell = Nothing
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To find the pairing key of each TV you will need to get your IT department to ensure that the IP addresses are static and then tell you what the ip address is of each TV. You can then send the following command, at the windows command prompt, to each TV in turn and read the pairing key off the screen...

C:\>python c:\display\lgcommander.py --host 10.44.18.15   <--your TV IP address

If Python isn't registered correctly in the Windows registry you will need to set the Python environment path
before python will run...

C:\>path %path%;C:\Program Files\Python_34    <--the path containing Python.exe