Shutdown after inactivity instead of Sleep

Vinwiesel

Member
Jan 26, 2011
163
0
0
Is this possible in windows 7? It seems that sleep and hybrid sleep are your only options, but I have 7+ year old system mixed with an SSD and >2t hdd's, and sleep simply does not work properly no matter what is done. So my only options are to leave it running 24/7 unless shut down manually, or do a hard reset whenever it tries to sleep and fails.

There are numerous posts about how to set shutdown timers, and use task scheduler to shut down at certain times, as well as threads on how to fix sleep problems, but I can find nothing regarding replacing sleep with shutdown in windows 7. What I really need is a way to be able to set the inactivity timer under power options, but have it shut down instead of sleep.

Has anyone done this? Is it possibly as simple as a registry setting, or editing shutdown.exe?
 

Ketchup

Elite Member
Sep 1, 2002
14,545
236
106
Hibernate is what you want. Does the same thing as a shutdown, but also saves everything in memory to a file so that when you boot it back up, it will come back to where you left it.
 

bononos

Diamond Member
Aug 21, 2011
3,888
157
106
Is this possible in windows 7? It seems that sleep and hybrid sleep are your only options, but I have 7+ year old system mixed with an SSD and >2t hdd's, and sleep simply does not work properly no matter what is done. So my only options are to leave it running 24/7 unless shut down manually, or do a hard reset whenever it tries to sleep and fails.
.....


Very old hardware may not support the very low power sleep states. And the bios settings must be set correctly. I think win7 sleep on a desktop install is hybrid sleep(or hibernate) by default.
 

Vinwiesel

Member
Jan 26, 2011
163
0
0
This is an old AthlonX2, with pretty limited options in the bios. I've tried changing the sleep states in the bios, but any change had no effect, or made things worse. With XP, sleep never worked on this system, but it had an option to shut down after inactivity which worked great.

On a dual-boot system it is not convenient to sleep/hibernate because you don't necessarily want it loading up Windows again. Surely there is some way to just make it shut down.

Since Sleep, and hybrid sleep are the only options on a desktop, can Win7 be set to identify the system as a laptop? I believe that then there is an option for shutdown.
 

Steltek

Diamond Member
Mar 29, 2001
3,042
753
136
If you have the problem machine networked (or have a virtual machine somewhere which can network with the problem machine), you might be able to install the Windows Remote Server Administration tools on that other machine/VM, then turn on the Group Policy Management Console. You could then use the GPMC to edit the group policy on the problem machine across the network connection to create a custom power plan for the problem machine.

If nothing else, you could likely set a group power policy action on the problem machine to force a shutdown after a set period of inactivity using the SHUTDOWN command. Of course, by doing this, any unsaved work would be lost if anything was running at the time of the shutdown.

However, this might be your only other option based upon your description of the issue.

I guess you've checked to see if there is a newer updated BIOS for your motherboard than the one installed?
 

Vinwiesel

Member
Jan 26, 2011
163
0
0
If nothing else, you could likely set a group power policy action on the problem machine to force a shutdown after a set period of inactivity using the SHUTDOWN command.

Could you expand on this? I believe if I had an .exe which would issue a shutdown command, I could use an app to run it after inactivity. I have used an autoshutdown app, but it only works about 1 out of 3 times, but it does have the ability to run a program prior to shutting down.
 

Steltek

Diamond Member
Mar 29, 2001
3,042
753
136
Could you expand on this? I believe if I had an .exe which would issue a shutdown command, I could use an app to run it after inactivity. I have used an autoshutdown app, but it only works about 1 out of 3 times, but it does have the ability to run a program prior to shutting down.

Actually for what you are wanting to do, maybe you can just try scheduling a task which repeats every 45 minutes that only runs if the computer has been idle for 90 minutes. There is a SHUTDOWN command line utility that can be used to force a shutdown.

Start Task Scheduler, and click on Create Task (not Create Basic Task). Set the Trigger to 'On Idle', with Repeat Task set to 45 minutes and Duration to Indefinitely. Under Actions, enter the program to run as SHUTDOWN with arguments set to /s /f /t 0 (where /s shuts down the computer, /f forces all programs to end without notification, /t 0 causes the shutdown to happen immediately with no shutdown timer shown). Under Conditions, check to Start the task only if the computer is idle for and enter the time as 90 minutes (the condition that must also be satisified in addition to the trigger event for the task to run).

In theory, this task should force a shutdown if and only if the computer is idle and has been idle for at least 90 minutes.

Try this and see if it does what you need it to do.
 
Last edited:

bononos

Diamond Member
Aug 21, 2011
3,888
157
106
This is an old AthlonX2, with pretty limited options in the bios. I've tried changing the sleep states in the bios, but any change had no effect, or made things worse. With XP, sleep never worked on this system, but it had an option to shut down after inactivity which worked great.

On a dual-boot system it is not convenient to sleep/hibernate because you don't necessarily want it loading up Windows again. Surely there is some way to just make it shut down.

Since Sleep, and hybrid sleep are the only options on a desktop, can Win7 be set to identify the system as a laptop? I believe that then there is an option for shutdown.

An AX2 should be able to sleep on XP. Maybe its a problem with the mb/bios.
 

Vinwiesel

Member
Jan 26, 2011
163
0
0
Actually for what you are wanting to do, maybe you can just try scheduling a task which repeats every 45 minutes that only runs if the computer has been idle for 90 minutes. There is a SHUTDOWN command line utility that can be used to force a shutdown.

Start Task Scheduler, and click on Create Task (not Create Basic Task). Set the Trigger to 'On Idle', with Repeat Task set to 45 minutes and Duration to Indefinitely. Under Actions, enter the program to run as SHUTDOWN with arguments set to /s /f /t 0 (where /s shuts down the computer, /f forces all programs to end without notification, /t 0 causes the shutdown to happen immediately with no shutdown timer shown). Under Conditions, check to Start the task only if the computer is idle for and enter the time as 90 minutes (the condition that must also be satisified in addition to the trigger event for the task to run).

In theory, this task should force a shutdown if and only if the computer is idle and has been idle for at least 90 minutes.

Try this and see if it does what you need it to do.

Just wanted to update that this is working pretty well for me. I wasn't aware that tasks could be set up to trigger on idle. It reliably shuts down my computer after inactivity, and can easily be disabled/enabled as desired. I got errors when I tried to add all the arguments to the shutdown command, but it has been working reliably without them. Thanks Steltek!
 

sm625

Diamond Member
May 6, 2011
8,172
137
106
Here is an autohotkey script I wrote which origianlly was designed to sleep after 10 minutes of idle, including no sound output. It will not sleep or shut down as long as there is audio or mouse/kb activity.

I modified it to shutdown for you instead of sleep. I use this script on several machines and it works great. Follow the instructions in the top few comments. Compile the script into an exe and add a shortcut to it in your startup folder.



Code:
;To use this script you must first be running AutoHotkey L 110703 or newer to guarantee compatibility
; (Choose the unicode 32 bit version when installing)
;AND you must download VA21.zip from:
; http://www.autohotkey.com/community/viewtopic.php?f=2&t=23792
; Once VA21.zip is downloaded, locate your Autohotkey folder and create a subfolder called "Lib"
; Place VA.ahk in that Lib folder
;
;Note: This will not work on win XP or older, since it uses the vista audio whatchamacallit

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
#SingleInstance, Force
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;This variable controls how many minutes of idle time are needed before sleeping
idletime := 10

;Convert minutes to milliseconds
idletime *= 1000*60

AudioIdleCount := 0

;Setup the timer 

;Set the timer to such a length that will allow us to check the sound 
; output level 6 times during the 2nd half of the idle period
; note that we're going to skip audio monitoring during the first half of the idle period

slice := idletime / 12

Settimer, IdleTimer, %slice%



;the next 3 lines are debug code

;debugtime := 0
;TrayTip, Idletest, Idletest`nDebug Info, 20, 17
;SetTimer, RemoveTrayTip, 5000




return


IdleTimer:

;Force AudioIdleCount to zero for the first half of the idle period
if(A_TimeIdlePhysical < (slice*6))
{
  AudioIdleCount := 0
  return
}

;Check for mouse/kb input during 2nd half of idle period
if(A_TimeIdlePhysical < (slice*(AudioIdleCount+6)))
{
  return
}

;continue only if mouse/keyboard are idle


audioMeter := VA_GetAudioMeter()

VA_IAudioMeterInformation_GetMeteringChannelCount(audioMeter, channelCount)

; "The peak value for each channel is recorded over one device
;  period and made available during the subsequent device period."
VA_GetDevicePeriod("capture", devicePeriod)

; Get the peak value across all channels.
VA_IAudioMeterInformation_GetPeakValue(audioMeter, peakValue) 
   
if(peakValue < 0.00001)
{
    AudioIdleCount++
}
else
{
    AudioIdleCount := 0  ;we still have some sound playing, so reset the counter
}

if(AudioIdleCount < 7)
  return

;MsgBox, idle!

;Set this back to zero so it will stay awake once it wakes back up!
AudioIdleCount := 0

  
; Call the Windows API function "SetSuspendState" to have the system suspend or hibernate.
; Windows 95/NT4: Since this function does not exist, the following call would have no effect.
; Parameter #1: Pass 1 instead of 0 to hibernate rather than suspend.
; Parameter #2: Pass 1 instead of 0 to suspend immediately rather than asking each application for permission.
; Parameter #3: Pass 1 instead of 0 to disable all wake events.

;DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
;uncomment the above line to sleep instead of shut down
Shutdown, 1

return


;debugging code

RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
;return

; To have a TrayTip permanently displayed, use a timer to refresh it periodically:
SetTimer, RefreshTrayTip, 1000
Gosub, RefreshTrayTip  ; Call it once to get it started right away.
return

RefreshTrayTip:
debugtime := A_TimeIdlePhysical / 1000
TrayTip, Idletest Debug Info, A_TimeIdlePhysical = %debugtime%`nAudioIdleCount = %AudioIdleCount%, , 16
return
 
Last edited: