INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: VBS Script to stop playback help...  (Read 1311 times)

muzicman0

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1239
VBS Script to stop playback help...
« on: February 21, 2015, 09:59:01 am »

I have created a very basic script in VBS that I am using in Theater view to stop playback after a certain amount of time (I have 3 scripts, 30, 60, and 90 minutes).  Used for watching TV at night, so when my wife falls asleep, the TV doesn't run all night.

I would like to add some sort of code to confirm the selection, because as it is, there is no feedback that the timer is actually running...I also would like it to work with a remote (my remote sends left/right cursor commands, so should be fairly easy).

Here is the code I am trying:
Code: [Select]
x=msgbox("Are you sure you want to stop playback after 30 minutes?" ,vbSystemModal + vbYesNo, "Stop Playback")
if x = vbYes then
Wscript.sleep 1800000
CreateObject("Wscript.Shell").Run "C:\Windows\System32\MC20.exe /MCC 10002"
end if
The problem is, that the msgbox doesn't have focus, so my remote commands are being sent to MC instead of the msgbox...

I was hoping someone here might have a more elegant solution, or perhaps there is a built-in way to do what I want...

For now, I just took out the msgbox, and am living with no feedback, or cancel option, but that is not a good longterm solution.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: VBS Script to stop playback help...
« Reply #1 on: February 21, 2015, 12:43:31 pm »

You could use WScript.Shell's Popup command instead of MsgBox.  This allows you to set a timeout on the popup so it'll auto-dismiss.

http://ss64.com/vb/popup.html
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

muzicman0

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1239
Re: VBS Script to stop playback help...
« Reply #2 on: February 21, 2015, 01:17:39 pm »

Perfect, thanks...here is what I hope is the final code.  It will kill any previous scripts running (as long as they aren't the same time choice - IE: if I had previously chosen a 30 minute timeout, and then choose a 90 minute timeout, then the script for the 90 minutes will kill the 30 minute script):
Code: [Select]
'Kill any of my scripts already running

Dim strScriptToKill1
Dim strScriptToKill2
    strScriptToKill1 = "Stop Jriver_60.vbs"
    strScriptToKill2 = "Stop Jriver_90.vbs"

Dim objWMIService, objProcess, colProcess

    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colProcess = objWMIService.ExecQuery ( _
        "Select * from Win32_Process " & _
        "WHERE (Name = 'cscript.exe' OR Name = 'wscript.exe') " & _
        "AND Commandline LIKE '%"& strScriptToKill1 &"%'" _
    )
    For Each objProcess in colProcess
        objProcess.Terminate()
    Next

    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colProcess = objWMIService.ExecQuery ( _
        "Select * from Win32_Process " & _
        "WHERE (Name = 'cscript.exe' OR Name = 'wscript.exe') " & _
        "AND Commandline LIKE '%"& strScriptToKill2 &"%'" _
    )
    For Each objProcess in colProcess
        objProcess.Terminate()
    Next

'Set the Stop time - with a 10 second timeout

Set objShell = Wscript.CreateObject("Wscript.Shell")
intButton = objShell.Popup("Stop playback in 30 minutes?", 10,"Stop Playback", 20)

if intButton = vbYes or intButton= -1 then
Wscript.sleep 1800000
CreateObject("Wscript.Shell").Run "C:\Windows\System32\MC20.exe /MCC 10002"

end if

I'm sure it could be more efficient, but I haven't done any real programming since VB6 days.
Logged

muzicman0

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1239
Re: VBS Script to stop playback help...
« Reply #3 on: February 21, 2015, 01:31:18 pm »

oh, and I also built a cancel all script which will kill all 3 choices.  It seems to work well.
Logged
Pages: [1]   Go Up