Copy Prohibited message kills video

Help with tuners from ATI, Hauppauge, AverMedia and more.
barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#41

Post by barnabas1969 » Fri Feb 28, 2014 4:10 pm

OK, here's my script. It's pretty simple. You'll need to add a scheduled task that runs with highest privileges (check the box on the General tab for the task's properties that says "run with highest privileges"). In the arguments for the action in your scheduled task, enter the number of minutes you want the script to keep trying. This argument is mandatory. For example, if you want it to keep trying for 3 hours, enter 180 as the argument.

Save this as a file with a .bat extension:

Code: Select all

set i=0

:BEGINCHECK
rem  Check for powercfg requests to keep the PC awake.  If one is found,
rem  goto WAITSOMETIME to wait 60 seconds before trying again.  If you
rem  want, you can add more checks for other processes by simply adding
rem  another pair of powercfg/if statements like what is shown below.
powercfg -requests | find "ehrec.exe"
if %ERRORLEVEL% == 0 goto :WAITSOMETIME
powercfg -requests | find "ehshell.exe"
if %ERRORLEVEL% == 0 goto :WAITSOMETIME

rem  Finally, let's check to see if a Media Center update is in progress.
rem  we don't want to reboot until that's finished.
tasklist /FI "IMAGENAME eq mcupdate.exe" | find "mcupdate.exe"
if %ERRORLEVEL% == 0 goto :WAITSOMETIME

rem  If we got here, then none of the processes above are running and
rem  it is safe to reboot the PC.
shutdown /r /t 0
goto :FINISH

:WAITSOMETIME
rem  Increment the counter "i".  If it is greater than the first argument,
rem  then give up.  Otherwise, use the choice command to force the script
rem  to wait 60 seconds before checking again.
set /A i=%i% + 1
if %i% GTR %1 goto :FINISH
choice /C YN /T 60 /D Y
goto :BEGINCHECK

:FINISH
Now, you need to understand that this will cause a command window to appear for the duration of the script. There's another thread around here by richard1980 with a simple VBScript that will cause your script to run hidden. Well, it turns out that you can check the "Hidden" box on the General tab in the scheduled task, and it hides the window. I thought I tested that in the past and it didn't work. I just tested it on my PC, and it works fine.
Last edited by barnabas1969 on Fri Feb 28, 2014 4:34 pm, edited 1 time in total.

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#42

Post by barnabas1969 » Fri Feb 28, 2014 4:23 pm

I edited my post above to add a check for a Media Center update in progress.

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#43

Post by barnabas1969 » Fri Feb 28, 2014 4:34 pm

I just scheduled it to run daily at 2:30am, and to keep checking for 240 minutes (4 hours).

I also ran it manually while I was watching live TV. It didn't reboot until I stopped live TV. I'm pretty happy with that.

About the only thing I can think to add is some kind of logging. That could be accomplished by adding the following echo statement just before the shutdown command in the script:

Code: Select all

echo System Rebooted at %date% %time% >>"<insert path to file here>"

KevinC25

Posts: 32
Joined: Tue Jul 30, 2013 9:47 pm
Location:

HTPC Specs: Show details

#44

Post by KevinC25 » Fri Feb 28, 2014 7:53 pm

Thanks Barnabas, this looks great. I plan on doing some experimentation over the weekend and will report back.

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#45

Post by barnabas1969 » Fri Feb 28, 2014 8:42 pm

Yeah, I tested it manually on mine by clicking "Run" on the task in Task Scheduler. It worked fine. I played a TV show in Media Center before I ran the task, and waited several minutes. It didn't reboot until about 20 seconds after I stopped playback.

I expect it to work fine. A word of caution though... I didn't include a check to see if an extender is connected, so it will reboot even if extenders are connected (but not if they are playing). If you want to prevent reboot when an extender is connected (and not playing), add a line to look for the McrMgr.exe process (it's case sensitive unless you add the /i switch to the find command).

Back when I allowed my old HTPC to sleep, I let MCE Standby Tool (MST) handle the daily reboots. However, when I setup this new PC to stay awake all the time, I tried using MST for the reboot, but when I set it to stay awake all the time, MST won't do the automatic reboot.

So, now I've uninstalled MST and will let this script handle it from now-on.

Something I should mention... if you use the Netflix plugin in Media Center, this script will reboot the PC while you are watching something in Netflix. This is because the Netflix plugin, which runs under ehexthost.exe, does not request the PC to stay awake... and neither does ehshell.exe during this type of playback. If you search around, I have a solution for that... I wrote a little program named watch_ehexthost32.exe that was supposed to be used with MST (to prevent MST from putting the PC to sleep while you're watching Netflix).

If you want to do something similar to what that program does, you could add the following commands to the batch script I posted above. Add them just after the check for mcupdate.exe.

Use this version if you use 64 bit Windows:

Code: Select all

netstat -bn | find /i "ehexthost32.exe"
if %ERRORLEVEL% == 0 goto :WAITSOMETIME
Use this version if you use 32 bit Windows:

Code: Select all

netstat -bn | find /i "ehexthost.exe"
if %ERRORLEVEL% == 0 goto :WAITSOMETIME

Space

Posts: 2838
Joined: Sun Jun 02, 2013 9:44 pm
Location:

HTPC Specs: Show details

#46

Post by Space » Sat Mar 01, 2014 6:38 am

If I am following this correctly, I believe Kevin was looking to reboot the Prime, not the PC.

Your script can be used with some minor changes to do this.

Again, I have not tested any of this, so no guarantee it will work, but at least it may give an idea of how it can be done.

Set deviceid1 to the device ID of your Prime (you can use deviceid2 if you have a second Prime).
If you have more than one Prime, you will have to add 3 more lockkey lines addressing the second device as well as an additional restart line. The script will require all tuners on all devices to be idle before it will reboot either of them.

I removed the check for ehshell.exe since I believe this will be running if you are watching a recorded show, which should not prevent the Prime from being rebooted. I kept the check for ehrec.exe, as this prevents the Prime from being rebooted immediately before WMC tries to use it to record a scheduled show.

The checking of the Prime tuners directly should prevent a reboot if anyone is using the tuners for any purpose (even if not from the WMC PC).

Code: Select all

set i=0

:BEGINCHECK
rem  Check for powercfg requests to keep the PC awake.  If one is found,
rem  goto WAITSOMETIME to wait 60 seconds before trying again.  If you
rem  want, you can add more checks for other processes by simply adding
rem  another pair of powercfg/if statements like what is shown below.

rem  Check if a recording is in progress or if one is about to be initiated
powercfg -requests | find "ehrec.exe"
if %ERRORLEVEL% == 0 goto :WAITSOMETIME

rem  If any of the tuners are in use (watching Live TV or perhaps another device is accessing a tuner), then do no reboot the HDHR Prime.
rem  Duplicate this section and replace deviceid1 with deviceid2 in the duplicated section if you have a second Prime

rem  Change deviceid1 to the device ID of the Prime
set deviceid1="FFFFFFFF"
"%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" %deviceid1% get /tuner0/lockkey | find "None"
if NOT %ERRORLEVEL% == 0 goto :WAITSOMETIME
"%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" %deviceid1% get /tuner1/lockkey | find "None"
if NOT %ERRORLEVEL% == 0 goto :WAITSOMETIME
"%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" %deviceid1% get /tuner2/lockkey | find "None"
if NOT %ERRORLEVEL% == 0 goto :WAITSOMETIME

rem  If we got here, then none of the processes above are running and
rem  it is safe to reboot the HDHR Prime.

"%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" %deviceid1% set /sys/restart self

rem  Uncomment this to reboot second Prime
rem  "%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" %deviceid2% set /sys/restart self

goto :FINISH

:WAITSOMETIME
rem  Increment the counter "i".  If it is greater than the first argument,
rem  then give up.  Otherwise, use the choice command to force the script
rem  to wait 60 seconds before checking again.
set /A i=%i% + 1
if %i% GTR %1 goto :FINISH
choice /C YN /T 60 /D Y
goto :BEGINCHECK

:FINISH

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#47

Post by barnabas1969 » Sat Mar 01, 2014 12:17 pm

Yes, that all makes sense if you want to reboot the prime. Your script takes the extra step of checking to see if the tuners are in use, which is necessary because the prime could be in use by a different computer or other devices like tablets and phones.

User avatar
UCBearcat

Posts: 249
Joined: Sat Jan 28, 2012 12:08 am
Location: Cincinnati

HTPC Specs: Show details

#48

Post by UCBearcat » Sat Mar 01, 2014 2:50 pm

barnabas1969 wrote:ehexthost.exe (and ehexthost32.exe on 64 bit systems) is the Extensbility Host. It runs anytime you have an add-in loaded in Media Center. It does not indicate that an extender is connected, only that an add-in is running inside the Media Center shell. The shell (ehshell.exe) is only loaded when the Media Center GUI is running, which includes extenders..
Good to know on the ehexthost process. When I quickly set this up for myself several months back, I just looked for any running processes that were tied to the extender. When I launch any of my extenders, there are 4 running processes that appear and are running as the user "Mcx1-WMCPC." Every other media center process seems to use the "eh" prefix, so I just assumed ehexthost.exe was the EXTender HOST process. ;)
Fortunately, for my needs, it has worked for me so far. But, now that you've thrown together a much more involved script - I may rethink how I do it. But, you know what they say. If it ain't broke - don't fix it. And mine isn't broke, yet. 8-)
I do like the idea of checking and re-checking every minute for a predefined duration. Right now, if the extender gets left on by accident (which does happen), the PC won't reboot on the scheduled interval. This check/re-check would combat that occurrence.

@Kevin and Space. I read on the SD forum that they suggested just restarting the 'ehrecvr' service instead of a reboot of the Prime or Media Center PC. Have either of you had a chance to test this out. I was going to give it a whirl, but I wanted to check w/ you guys first - as the test will take at least 47 hours to run.

KevinC25

Posts: 32
Joined: Tue Jul 30, 2013 9:47 pm
Location:

HTPC Specs: Show details

#49

Post by KevinC25 » Sat Mar 01, 2014 3:25 pm

What a great world! after thinking things through I wrote on my to-do list for today to adapt Barnabas's script for the primes reboot and also that it might be a good idea to add in the lockkey test suggested by Jasonl... and this morning Space has already figured it out for us! Seriously, on first review this looks like exactly what I'm looking for! Thanks Space!

As far as just restarting the 'ehrecvr' service instead of a reboot of the Prime or Media Center PC is concerned, I tried running that at a test on Thursday afternoon and am running some test recordings today: if it worked, the test recording over the 47 anniversary of the previous problem (this morning Pacific) will be fine and one this afternoon will fail. We'll see. However, when I tested it I deliberately left two extenders switched on (not streaming, just on) to see what would happen with that process in normal use, and they didn't like it - to get them working properly again I had to pull their power cables out and hard reboot - so that route is not my preference anyway. Either way, after I see how that goes I'll be able to start running batch file tests.

KevinC25

Posts: 32
Joined: Tue Jul 30, 2013 9:47 pm
Location:

HTPC Specs: Show details

#50

Post by KevinC25 » Fri Mar 07, 2014 3:46 pm

Just wanted to report that after methodically checking out that the "47 hour bug" was indeed deferred for me by rebooting the tuners, I began experimenting step by step and line by line with the batch file commands from Spaceclick's last version, then the same approach to the batch files themselves and to scheduled tasks and now seem to have things working. I have set two scheduled tasks to run the file/reboot the tuners, one at roughly 1am and one at 1pm and the 1am task ran successfully overnight. What I like about this method is that the reboot of the tuners is very quick and doesn't mess with anything else.

For the record in case somebody else uses this, I found that when I use lines like:

if NOT %ERRORLEVEL% == 0 goto :WAITSOMETIME

in a batch file although it looks like that when it runs in the cmd window, I have to type it as

if NOT %ERRORLEVEL%==0 goto :WAITSOMETIME

otherwise it does not work.

Also, for some reason set deviceid1 etc did not work for me, so I have left that out and simply used my Prime ID in each instance of %deviceid1%.

Bottom line, it seems to be working fine and I wanted to say thanks again to you all for the great help!

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#51

Post by barnabas1969 » Fri Mar 07, 2014 4:00 pm

The reboot of the PC has been working on mine just fine since I wrote it about a week ago. It has rebooted at 2:30am every night, except one where it waited an hour or so (because someone was watching TV). It works with the spaces in the if statement, so I don't understand why that didn't work for KevinC25. It's fine to remove the spaces around the == though.

Space

Posts: 2838
Joined: Sun Jun 02, 2013 9:44 pm
Location:

HTPC Specs: Show details

#52

Post by Space » Fri Mar 07, 2014 6:20 pm

Not sure why it does not work with the spaces, but I am not normally a batch file scripter, so don't know the idiosyncrasies. I would normally use the "!=" operator but a Google search told me that batch scripts use the "NOT" method, so that is what I used. Like I said I didn't test the script, so if you got it working with some changes, you might want to post it so others can benefit.

Thanks

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#53

Post by barnabas1969 » Fri Mar 07, 2014 6:23 pm

You can do this:

Code: Select all

if %ERRORLEVEL% NEQ 0 goto :WAITSOMETIME

KevinC25

Posts: 32
Joined: Tue Jul 30, 2013 9:47 pm
Location:

HTPC Specs: Show details

#54

Post by KevinC25 » Sun Mar 09, 2014 7:54 pm

This is the code I've used in the batch file. (Note that I've replaced the actual 8-digit IDs of my two primes by 1234ABCD and 5678EFGH.)

In task scheduler, I have set up two tasks, which run the batch file at 1252am and 1252pm respectively. Otherwise they are identical tasks. I put the number 460 as argument: this means the "waitsometime" runs 460 times before giving up, i.e for 460 minutes or nearly 8 hours. This is because I set the task to cancel if not completed after 8 hours. (I would have liked to have the task cancel after say 11 hours and the "wait some time" be a bit less than that, but Windows task scheduler doesn't give you that much flexibility.) I have it set to "wake to run" (though my machine currently never sleeps), run hidden, highest level of privileges, and to run whether the user is logged on or not (in case the computer has rebooted for some reason say) which requires you to type your user password to confirm. So far so good in my tests.

Code: Select all

    set i=0

    :BEGINCHECK
    rem  Check if a recording is in progress or if one is about to be initiated. If so,
    rem  then do not reboot the HDHR Primes.
    powercfg -requests | find "ehrec.exe"
    if %ERRORLEVEL%==0 goto :WAITSOMETIME

    rem  If any of the tuners are in use (watching Live TV or perhaps another device
    rem  is accessing a tuner), then do not reboot the HDHR Primes.

    "%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" 1234ABCD get /tuner0/lockkey | find "none"
    if NOT %ERRORLEVEL%==0 goto :WAITSOMETIME
    "%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" 1234ABCD get /tuner1/lockkey | find "none"
    if NOT %ERRORLEVEL%==0 goto :WAITSOMETIME
    "%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" 1234ABCD get /tuner2/lockkey | find "none"
    if NOT %ERRORLEVEL%==0 goto :WAITSOMETIME

    "%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" 5678EFGH get /tuner0/lockkey | find "none"
    if NOT %ERRORLEVEL%==0 goto :WAITSOMETIME
    "%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" 5678EFGH get /tuner1/lockkey | find "none"
    if NOT %ERRORLEVEL%==0 goto :WAITSOMETIME
    "%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" 5678EFGH get /tuner2/lockkey | find "none"
    if NOT %ERRORLEVEL%==0 goto :WAITSOMETIME

    rem  If we got here, then none of the processes above are running and
    rem  it is safe to reboot the HDHR Primes.

    "%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" 1234ABCD set /sys/restart self

    "%programfiles%\silicondust\hdhomerun\hdhomerun_config.exe" 5678EFGH set /sys/restart self

    goto :FINISH

    :WAITSOMETIME
    rem  Increment the counter "i".  If it is greater than the first argument,
    rem  then give up.  Otherwise, use the choice command to force the script
    rem  to wait 60 seconds before checking again.
    set /A i=%i% + 1
    if %i% GTR %1 goto :FINISH
    choice /C YN /T 60 /D Y
    goto :BEGINCHECK

    :FINISH
I hope this useful thread helps some other people who are suffering from this "47-hour bug". If so, remember to say thanks to @barnabas1969, @UCBearcat and @Space here and to @Signcarver and @Jasonl on the Silicondust forum, without whose help I would never have got my system working so reliably!

Post Reply