Try the below batch script, it rely's on the the system uptime. Run this when you think it is appropriate, with the Scheduler
@echo off
setlocal enabledelayedexpansion
for /f "tokens=2 delims=," %%a in ('systeminfo ^| findstr Boot ^| findstr System') do (
set output=%%a
set /a hrs=!output:~1,1!
set mins=!output:~3,2!
::echo !output!
::echo !hrs!
::echo !mins!
if !hrs! == 5 (
if !mins! == 50 (
shutdown -s -f -t 100
)
)
)
Well that is the idea, tweak as required
Explanation.
- Extract the time that the computer was switched on,
systeminfo ^| findstr Boot ^| findstr System
systeminfo has a lot of information in there, So we are filtering only the parameter that we need we are looking for.
eg,
C:\Users>systeminfo | findstr Boot |findstr System
System BootTime: 12/4/2014, 7:20:37 AM
- Select the time field only that is separated by the comma
for /f "tokens=2 delims=," %%a in ('systeminfo ^| findstr Boot ^| findstr System') do (
set output=%%a
and in that entire string only select the 1st character ( 1 space), the 3rd and 4th character (2 space)
set /a hrs=!output:~1,1!
set mins=!output:~3,2!
To give only the hr and the minute
- IF function to shutdown if the time is a match.
if !hrs! == 5 (
if !mins! == 50 (
shutdown -s -f -t 100
PS: The bellow is the comment to see, if there is any mistake in the code,
::echo !output!
::echo !hrs!
::echo !mins!
2Hack: when the PC is booted up, write a value via a script, such as the on time. Save this value to a file on your PC. Then, at shutdown time, check the value of this file and act accordingly. – Dave – 2014-12-04T08:47:12.937
Cool idea, wrote a script for it, without the need to save it. :) – Charm_quark – 2014-12-04T09:57:17.707