how to add a delay between shutdown and reboot.

A place to talk about GPUs/Motherboards/CPUs/Cases/Remotes, etc.
lurch66

Posts: 244
Joined: Fri Jun 10, 2011 4:32 am
Location: Queen Creek AZ

HTPC Specs: Show details

how to add a delay between shutdown and reboot.

#1

Post by lurch66 » Thu Mar 15, 2012 4:12 am

I just purchased a power strip that cuts power to some of its outlets when the master device shuts down for the purpose of rebooting my tuning adapter every time I reboot my pc. It works great if I shutdown my pc and than turn it back on but if I do a standard reboot the pc is not off long enough to trigger the relay in the power strip. Is there a way to delay the time by 3 seconds or so between shutdown and reboot maybe with a reg edit or modifying a batch command.

I am currently using MCE standby tool to reboot my pc everyday when not in use. I unfortunately need to do this to keep the tuning adapter working well. Maybe there is a way to insert the delay/batchfile in that program. Thank's in advance for any advice.

richard1980

Posts: 2623
Joined: Wed Jun 08, 2011 3:15 am
Location:

HTPC Specs: Show details

#2

Post by richard1980 » Thu Mar 15, 2012 4:27 am

A reboot does not cut power at all. Only a full shutdown will completely cut power. To accomplish your goal, you need to look at a home automation solution that can kill power to the outlet that the TA is plugged into. Something like this: http://www.smarthome.com/2456S3T/TimerL ... mer/p.aspx or this: http://www.smarthome.com/2456S3/Applian ... pin/p.aspx

erkotz

Posts: 1378
Joined: Mon Aug 22, 2011 9:23 pm
Location:

HTPC Specs: Show details

#3

Post by erkotz » Thu Mar 15, 2012 4:44 am

An APC masterswitch is basically an IP-enabled power strip. That may be another way to accomplish what you want.
Quality Assurance Manager, Ceton Corporation

lurch66

Posts: 244
Joined: Fri Jun 10, 2011 4:32 am
Location: Queen Creek AZ

HTPC Specs: Show details

#4

Post by lurch66 » Thu Mar 15, 2012 5:47 am

Thanks for the advice I did not know that a reboot does not cut power. Good thing the powerstrip was only $23. I can make adjustments so it will kill power when the pc is asleep but the computer only turns on 2 minutes before a recording and the tuning adapter takes 5-7 min to reboot. erkotz do you know of a way to set the Ceton to wake the pc say 10min before the recording.
My problem is I lose switched ch every 3 days or so and rebooting my tuning adapter while the pc is on fixes the problem every time. If I reboot it when the pc is off the problem remains. I went through about 5 adapters with no change and already submitted a support ticket with Ceton. It looks like a problem with the adapter not the Ceton so I was trying to do the automatic reboot as a permanent fix.

Beradon

Posts: 125
Joined: Sun Feb 26, 2012 5:03 pm
Location:

HTPC Specs: Show details

#5

Post by Beradon » Thu Mar 15, 2012 6:01 am

Here's a dumb idea.

So the Ceton starts recording 2 minutes before, set your PC clock to be off by 3 minutes (total of 5 minutes) since the Ceton will also record up to 3 minutes after so you'll get the whole program.

Be sure if you do this to disable the clock connecting to the time server and fixing itself.

I know playready will fail if the time is off too much, but I doubt 3 minutes is enough to fail that.

I'll try to think of something else, but its at least a stopgap.

Edit:

Here's a different idea:

Get one of those light timers and set it to kill the power for like 5 minutes a day in the middle of the day when you arent recording anything...

Make sure its three prong like this one:
http://www.amazon.com/Marineland-PA0401 ... 570&sr=8-1

You could plug the tuning adapter into that by itself without having to worry about killing/rebooting the HTPC or anything else.

erkotz

Posts: 1378
Joined: Mon Aug 22, 2011 9:23 pm
Location:

HTPC Specs: Show details

#6

Post by erkotz » Thu Mar 15, 2012 9:13 am

The InfiniTV doesn't wake the PC - that's a WMC (actually a scheduled task) function. You might be able to tweak it, but I've never tried so can't really offer a suggestion. What firmware is your TA running?
Quality Assurance Manager, Ceton Corporation

lurch66

Posts: 244
Joined: Fri Jun 10, 2011 4:32 am
Location: Queen Creek AZ

HTPC Specs: Show details

#7

Post by lurch66 » Thu Mar 15, 2012 1:33 pm

firmware 1402.
Thank you for all the advice I think I will try the digital timer to "unplug" it for 1 min a couple times a day. I don't want to mess with the clock as I finally have it syncing once a day reliably so it is very accurate.

barnabas1969

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

HTPC Specs: Show details

#8

Post by barnabas1969 » Thu Mar 15, 2012 4:28 pm

Lurch,

I am doing exactly what you are doing. My TA is connected to a "Smart" power strip. When my PC sleeps, the TA turns off.

In my case, the PC wakes 5 minutes before a scheduled recording. I can't remember where I set this up, but it's just a registry setting that controls the amount of time before a recording for the PC to wake. Five minutes gives plenty of time for the TA to boot and be ready to go.

richard1980

Posts: 2623
Joined: Wed Jun 08, 2011 3:15 am
Location:

HTPC Specs: Show details

#9

Post by richard1980 » Fri Mar 16, 2012 12:07 am

I'm pretty sure 5 minutes is the default setting. At least that's the behavior I get on my system...when it actually goes to sleep without hanging.

lurch66

Posts: 244
Joined: Fri Jun 10, 2011 4:32 am
Location: Queen Creek AZ

HTPC Specs: Show details

#10

Post by lurch66 » Fri Mar 16, 2012 5:56 am

barnabas1969 wrote:Lurch,

I am doing exactly what you are doing. My TA is connected to a "Smart" power strip. When my PC sleeps, the TA turns off.

In my case, the PC wakes 5 minutes before a scheduled recording. I can't remember where I set this up, but it's just a registry setting that controls the amount of time before a recording for the PC to wake. Five minutes gives plenty of time for the TA to boot and be ready to go.
So I spent the better part of an hour searching online for a way to change the amount of time before a recording to wake without any luck. I have a Cisco tuning adapter and it takes 10-15 min to reboot after being off for a wile. Do you have a Cisco as well or are you lucky enough to be running a Motorola. Thanks in advance for the help.

richard1980

Posts: 2623
Joined: Wed Jun 08, 2011 3:15 am
Location:

HTPC Specs: Show details

#11

Post by richard1980 » Fri Mar 16, 2012 11:48 am

FWIW, I tried finding the same thing before and couldn't. Ceton's WMC addin has a setting to wake 2 minutes earlier, but I never could get that to work.

I know the wake event for recordings is controlled by task scheduler (it's in Task Scheduler Library\Microsoft\Windows\Media Center\StartRecording), so in lieu of a registry setting, you could modify the wake time with scripting.

Edit: That task is modified by the OS each time the computer goes to sleep, so you'll want to create a different task that wakes the computer. Then create a script that reads the following registry value:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Service\Recording]
"NextRecordingAt"

Have that task execute schtasks.exe with the appropriate switches to change the start time of your custom task. You'll want to start the task 10 minutes earlier than the time listed in the registry key (this will wake your computer 15 minutes early). Keep in mind the registry uses Zulu time, not your local time zone. So you'll have to convert from Zulu to local.

Then you just get a utility to run a program before sleep, and have it run the script. There are several such utilities available.

You'll also want to make sure your sleep timeout is changed to >15 minutes.

barnabas1969

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

HTPC Specs: Show details

#12

Post by barnabas1969 » Fri Mar 16, 2012 1:11 pm

lurch66 wrote:
barnabas1969 wrote:Lurch,

I am doing exactly what you are doing. My TA is connected to a "Smart" power strip. When my PC sleeps, the TA turns off.

In my case, the PC wakes 5 minutes before a scheduled recording. I can't remember where I set this up, but it's just a registry setting that controls the amount of time before a recording for the PC to wake. Five minutes gives plenty of time for the TA to boot and be ready to go.
So I spent the better part of an hour searching online for a way to change the amount of time before a recording to wake without any luck. I have a Cisco tuning adapter and it takes 10-15 min to reboot after being off for a wile. Do you have a Cisco as well or are you lucky enough to be running a Motorola. Thanks in advance for the help.
I have a Cisco TA also. Mine only takes 1-2 minutes to get ready after being powered off. If yours takes 15 minutes, maybe you should try what someone else suggested... use a cheap timer to power off the TA once a day for a few minutes. Pick a time when you are least likely to have a recording starting. The TA is only accessed when you first start a recording, or when you change channels manually to a SDV channel. So, if you choose a time like 2:15am, when it's very unlikely for a show to begin (they usually start on the hour or on the half-hour), you should be OK.

richard1980

Posts: 2623
Joined: Wed Jun 08, 2011 3:15 am
Location:

HTPC Specs: Show details

#13

Post by richard1980 » Fri Mar 16, 2012 2:42 pm

I know I suggested the timer, but if it takes 15 minutes to boot the TA, I don't know if the timer is such a good idea. You never know when some movie is going to be scheduled to start at 2:20 AM, and I wouldn't like it if I missed a recording because the TA wasn't ready.

Because of that, I think scripting is the best solution. Either use scripting to create a wake event or use scripting to control the outlet power status. If I'm not mistaken, those Insteon devices can be controlled from the PC.

lurch66

Posts: 244
Joined: Fri Jun 10, 2011 4:32 am
Location: Queen Creek AZ

HTPC Specs: Show details

#14

Post by lurch66 » Sat Mar 17, 2012 3:10 am

Thank you for all the advice I will try them and let you know what worked. I did spend the money on the power strip so I would like to use it but if I need to by something else so be it. This is truly a great community with many knowledgeable people and I am great full to be a part of it.

lurch66

Posts: 244
Joined: Fri Jun 10, 2011 4:32 am
Location: Queen Creek AZ

HTPC Specs: Show details

#15

Post by lurch66 » Sat Mar 17, 2012 4:02 am

I found this in the reg edit

@%SystemRoot%\system32\powrprof.dll,-124,Allow Windows to automatically wake your computer from sleep on a timer for scheduled tasks and other programs.
It is located in Computer/HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\238C9FA8-0AAD-41ED-83F4-97BE242C8F20\BD3B718A-0680-4D9D-8AB2-E1D2B4AC806D

would changing the -124 to something like -900 seconds which is 15 min change the wake time. I suppose I could back up my registry and give it a shot.

richard1980

Posts: 2623
Joined: Wed Jun 08, 2011 3:15 am
Location:

HTPC Specs: Show details

#16

Post by richard1980 » Sat Mar 17, 2012 3:58 pm

OK, here's a script that will look at the registry to find the next scheduled recording time, and create a scheduled task that wakes the computer 10 minutes early. The registry key is already offset by 5 minutes, so this results in the computer waking 15 minutes before the recording actually starts. You can modify the time by changing the first line of the script.

You'll want to open notepad and paste the code in. Then save the file with a VBS extension. Then you'll need a program that can run programs before entering sleep. I believe MST can do this (see http://www.degroeneknop.nl/forum/index.php?topic=3717.0), and there are other programs as well. Whatever you use, have it run the VBS script before going to sleep.

If you can't get that to work, another option might be to update the script code to monitor the registry value that is referenced. That way any time the next scheduled recording is updated, this script automatically creates the wake task.

Here's the code:

Code: Select all

WakeEarlyMinutes=10	'change this to how many minutes earlier you want the computer to wake
ScheduledTask="WakeTA"	'change this change the name of the task that wakes the computer

function readFromRegistry (strRegistryKey)
	Dim WSHShell, value
	On Error Resume Next
	Set WSHShell=CreateObject("WScript.Shell")
	value=WSHShell.RegRead(strRegistryKey)
	readFromRegistry=value
	set WSHShell=nothing
end function

Function ConvertToLocalDate(sTime)
	Dim od, ad, oShell, atb, offsetMin
	Dim sHour, sMinute, sMonth, sDay
	Dim ResultDate
	od = CDate(Mid(sTime,9,2) & "-" & Mid(STime,6,2) & "-" & Mid(STime,1,4) & " " & Mid(STime,12,8))
	Set oShell = CreateObject("WScript.Shell")
	atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
	offsetMin = oShell.RegRead(atb)
	offsetMin = -(offsetMin+WakeEarlyMinutes)
	ad = dateadd("n", offsetMin, od)
	sMonth = Month(CDate(ad))
	If Len(sMonth) = 1 Then
		sMonth = "0" & sMonth
	End If
	sDay = Day(CDate(ad))
	If Len(sDay) = 1 Then
		sDay = "0" & sDay
	End If
	sHour = Hour(CDate(ad))
	If Len(sHour) = 1 Then
		sHour = "0" & sHour
	End If
	sMinute = Minute(CDate(ad))
	If Len(sMinute) = 1 Then
		sMinute = "0" & sMinute
	End If
	ConvertToLocalDate=(sMonth & "/" & sDay & "/" & Year(CDate(ad)))
End Function

Function ConvertToLocalTime(sTime)
	Dim od, ad, oShell, atb, offsetMin
	Dim sHour, sMinute, sMonth, sDay
	Dim ResultDate
	od = CDate(Mid(sTime,9,2) & "-" & Mid(STime,6,2) & "-" & Mid(STime,1,4) & " " & Mid(STime,12,8))
	Set oShell = CreateObject("WScript.Shell")
	atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
	offsetMin = oShell.RegRead(atb)
	offsetMin = -(offsetMin+WakeEarlyMinutes)
	ad = dateadd("n", offsetMin, od)
	sMonth = Month(CDate(ad))
	If Len(sMonth) = 1 Then
		sMonth = "0" & sMonth
	End If
	sDay = Day(CDate(ad))
	If Len(sDay) = 1 Then
		sDay = "0" & sDay
	End If
	sHour = Hour(CDate(ad))
	If Len(sHour) = 1 Then
		sHour = "0" & sHour
	End If
	sMinute = Minute(CDate(ad))
	If Len(sMinute) = 1 Then
		sMinute = "0" & sMinute
	End If
	ConvertToLocalTime=(sHour & ":" & sMinute)
End Function

NextRecordingAt=readfromRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Service\Recording\NextRecordingAt")
NextRecordingDate=ConvertToLocalDate(NextRecordingAt)
NextRecordingTime=ConvertToLocalTime(NextRecordingAt)
Set Wshell = WScript.CreateObject("WScript.Shell")
Task=("SCHTASKS /CREATE /F /SC ONCE /TN """ & ScheduledTask& """ /TR ""START"" /SD " & NextRecordingDate & " /ST " & NextRecordingTime)
Wshell.run Task,0,true
Const TASK_UPDATE = &H4
Const TASK_DONT_ADD_PRINCIPAL_ACE = &H10
Dim TaskName, EnableWakeToRun, objTaskService, objRootFolder, objTask, objDefinition
TaskName = ScheduledTask
Set objTaskService = CreateObject("Schedule.Service")
objTaskService.Connect
Set objRootFolder = objTaskService.GetFolder("\")
Set objTask = objRootFolder.GetTask ("\" & TaskName)
Set objDefinition = objTask.Definition
objDefinition.Settings.WakeToRun = true
objRootFolder.RegisterTaskDefinition objTask.Name, objDefinition, TASK_UPDATE or  TASK_DONT_ADD_PRINCIPAL_ACE, , , objDefinition.Principal.LogonType
Set objTaskService = CreateObject("Schedule.Service")
objTaskService.Connect
Set objRootFolder = objTaskService.GetFolder("\")
Set objTask = objRootFolder.GetTask (TaskName)

lurch66

Posts: 244
Joined: Fri Jun 10, 2011 4:32 am
Location: Queen Creek AZ

HTPC Specs: Show details

#17

Post by lurch66 » Sun Mar 18, 2012 3:59 am

This is great, thanks for going to the trouble. I already use MST so this should work like a charm. I will give this a shot and let you know.

lurch66

Posts: 244
Joined: Fri Jun 10, 2011 4:32 am
Location: Queen Creek AZ

HTPC Specs: Show details

#18

Post by lurch66 » Sun Mar 18, 2012 5:30 am

I am running the 64bit addition and it looks like MST updated some of the steps along with the location in the registry. Here is the link to the updated setup page.

http://www.degroeneknop.nl/forum/index. ... 565.0.html

richard1980

Posts: 2623
Joined: Wed Jun 08, 2011 3:15 am
Location:

HTPC Specs: Show details

#19

Post by richard1980 » Sun Mar 18, 2012 5:51 am

It really wasn't much trouble...I just copied snippets of code I found and did a little customizing to make it work for this scenario.

Here is the updated version of the code that will monitor the registry. Upon execution, it will check the registry to find the next scheduled recording, and create a task to wake the computer 10 minutes early. The script then goes into monitoring mode, where it will continue checking the registry every 1 second to see if the next scheduled recording time has changed, and if so, update the wake time.

There is no need to configure this script to run before entering sleep. Just have it run at startup or logon. I didn't mention this before, but in order to start the VBS script, just create a batch file with the following command:

start c:\folder\file.vbs

Here's the updated code (this is cleaned up a bit...still not the best example of code, but it gets the job done):

Code: Select all

WakeEarlyMinutes=10	'change this to how many minutes earlier you want the computer to wake
ScheduledTask="WakeTA"	'change this change the name of the task that wakes the computer
Dim NextRecordingAt
CreateWakeTask
Monitor

function readFromRegistry (strRegistryKey)
	Set WSHShell=CreateObject("WScript.Shell")
	value=WSHShell.RegRead(strRegistryKey)
	readFromRegistry=value
end function

Function ConvertToLocalDate(sTime)
	od = CDate(Mid(sTime,9,2) & "-" & Mid(STime,6,2) & "-" & Mid(STime,1,4) & " " & Mid(STime,12,8))
	Set oShell = CreateObject("WScript.Shell")
	atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
	offsetMin = oShell.RegRead(atb)
	offsetMin = -(offsetMin+WakeEarlyMinutes)
	ad = dateadd("n", offsetMin, od)
	sMonth = Month(CDate(ad))
	If Len(sMonth) = 1 Then
		sMonth = "0" & sMonth
	End If
	sDay = Day(CDate(ad))
	If Len(sDay) = 1 Then
		sDay = "0" & sDay
	End If
	sHour = Hour(CDate(ad))
	If Len(sHour) = 1 Then
		sHour = "0" & sHour
	End If
	sMinute = Minute(CDate(ad))
	If Len(sMinute) = 1 Then
		sMinute = "0" & sMinute
	End If
	ConvertToLocalDate=(sMonth & "/" & sDay & "/" & Year(CDate(ad)))
End Function

Function ConvertToLocalTime(sTime)
	od = CDate(Mid(sTime,9,2) & "-" & Mid(STime,6,2) & "-" & Mid(STime,1,4) & " " & Mid(STime,12,8))
	Set oShell = CreateObject("WScript.Shell")
	atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
	offsetMin = oShell.RegRead(atb)
	offsetMin = -(offsetMin+WakeEarlyMinutes)
	ad = dateadd("n", offsetMin, od)
	sMonth = Month(CDate(ad))
	If Len(sMonth) = 1 Then
		sMonth = "0" & sMonth
	End If
	sDay = Day(CDate(ad))
	If Len(sDay) = 1 Then
		sDay = "0" & sDay
	End If
	sHour = Hour(CDate(ad))
	If Len(sHour) = 1 Then
		sHour = "0" & sHour
	End If
	sMinute = Minute(CDate(ad))
	If Len(sMinute) = 1 Then
		sMinute = "0" & sMinute
	End If
	ConvertToLocalTime=(sHour & ":" & sMinute)
End Function

sub CreateWakeTask()
	NextRecordingAt=readfromRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Service\Recording\NextRecordingAt")
	NextRecordingDate=ConvertToLocalDate(NextRecordingAt)
	NextRecordingTime=ConvertToLocalTime(NextRecordingAt)
	Set Wshell = WScript.CreateObject("WScript.Shell")
	Task=("SCHTASKS /CREATE /F /SC ONCE /TN """ & ScheduledTask & """ /TR ""START"" /SD " & NextRecordingDate & " /ST " & NextRecordingTime)
	Wshell.run Task,0,true
	Const TASK_UPDATE = &H4
	Const TASK_DONT_ADD_PRINCIPAL_ACE = &H10
	TaskName = ScheduledTask
	Set objTaskService = CreateObject("Schedule.Service")
	objTaskService.Connect
	Set objRootFolder = objTaskService.GetFolder("\")
	Set objTask = objRootFolder.GetTask ("\" & TaskName)
	Set objDefinition = objTask.Definition
	objDefinition.Settings.WakeToRun = true
	objRootFolder.RegisterTaskDefinition objTask.Name, objDefinition, TASK_UPDATE or  TASK_DONT_ADD_PRINCIPAL_ACE, , , objDefinition.Principal.LogonType
	Set objTaskService = CreateObject("Schedule.Service")
	objTaskService.Connect
	Set objRootFolder = objTaskService.GetFolder("\")
	Set objTask = objRootFolder.GetTask (TaskName)
end sub

sub monitor()
	while(1)
		Wscript.sleep(1000)
		NextRecordingAtNew=readfromRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Service\Recording\NextRecordingAt")
		if NextRecordingAtNew <> NextRecordingAt Then
			CreateWakeTask
		end if
	wend
end sub

lurch66

Posts: 244
Joined: Fri Jun 10, 2011 4:32 am
Location: Queen Creek AZ

HTPC Specs: Show details

#20

Post by lurch66 » Sun Mar 18, 2012 6:49 am

OK so I copied your script into notepad and saved as a .vbs and set Microsoft windows based script host as the default program. I than through it in the start up folder and rebooted. the script started and I than put the pc to sleep and wo ho !!!!! 15min before the next recording the computer woke up. richard1980 thanks for the help you rock.

questions) how much system resources does it take to run this script checking the registry every 1 sec. I was unable to get it working in conjunction with mst so this seems to be the best way.

Thanks again for your help.

Post Reply