Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm used to not shutdown Windows but to sleeping it. I set up power button (PB) action to do it. When I want to shutdown I must go to start -> Shutdown. That's OK.

Now I think of a mechanism that will be hooked up to a PB. Should be started after I press PB but before OS will go to sleep. Something that will check few conditions (i.e. running backup, running AV scan, ...) and if true (something is running) prevent go to sleep.

Optionally: It would be nice to start the same "mechanism" before restart and shutdown (invoked not only from Start menu, but also by other software (i.e. installers) but with option to allow some sources (i.e. UPS software)

Generally: How to run something after PowerButton but before Sleeping. How to code (C#.NET, vbs, batch (preferred)) sleep prevention (cancellation).

share|improve this question
    
I can explain how to prevent Windows 7 automatically shutting down your Programs when you by accident press the shut down button. I know also how to stop Windows 7 from entering hibernation mode when a specific process is running (through Terminal). There is also a program that prevents Windows 7 from going to sleep when it is busy. But i am not sure if you are looking for this solutions. If you are interested i will post it here. –  Devid Mar 4 '13 at 15:25
    
Yes, Devid. Please share the secret. I'll try your ideas/apps. Thanx in advance. –  Juras.pl Mar 5 '13 at 10:36

1 Answer 1

Sometimes it may happen that you shut down your Windows 7 unintentionally. Windows 7 will then automatically shut down all your programs and and you might loose changes. But you can prevent this from happening. Here is how it is done:

Turn Off Auto Closing of Programs at Shutdown in Windows 7

Windows 7 Professional:

  • Press the Windows button and type in the search gpedit.msc. Right click on it and run with Administrator rights. Now go to Computer ConfigurationAdministrative TemplatesSystemShutdown Options. In the right hand side pane, you will find a value Turn off automatic termination of applications that block or cancel shutdown. Double click on it and choose Enabled. Click OK to save the settings and close the dialog.

gpedit.msc Turn Auto Closing of Programs

Windows 7 Home Edition:

  • For this version of Windows 7 you will have to hack the registry or just download turnoff_autoclose_policy_win7.zip. Just extract it on your desktop and double click on turnoff_autoclose_policy_win7.reg and click 'YES'. This will automatically add a New → DWORD (32-bit Value) to the registry key HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\System.

Powercfg Command-Line Options

  • In the command line you can type POWERCFG -REQUESTSOVERRIDE PROCESS name_of_the_process Display System and this will prevent Windows 7 to go to sleep while a certain process is running. I never used it so you must read the manual here.

    Usage: POWERCFG -REQUESTSOVERRIDE <CALLER_TYPE> <NAME> <REQUEST> Specifies one of the following caller type: PROCESS, SERVICE, DRIVER. This is obtained by calling the POWERCFG -REQUESTS command. Specifies the caller name. This is the name returned from calling POWERCFG -REQUESTS command. Specifies one or more of the following Power. Request Types: Display, System, Awaymode.

    Example: POWERCFG -REQUESTSOVERRIDE PROCESS wmplayer.exe Display System

    To remove the power request override, use the -REQUESTSOVERRIDE option, but do not specify any type of override (System, Display, AwayMode) as in the following example: POWERCFG -REQUESTSOVERRIDE PROCESS wmplayer.exe

"Insomnia" for Keeping Windows 7 Awake!

  • There is laso a programm that keeps your Windows 7 System Awake. It is called Insomnia and you can read everything about it from here. You can download here Insomnia.
share|improve this answer
    
1. "Turn Off Auto Closing of Programs at Shutdown in Windows 7" -> I want programs to be closed automatically on shutdown. Exceprion is when backup is running. 3. "Insomnia" -> First thought: start insomnia, backup, kill insomnia. Then a read that Insomnia will not interrupt user-requested sleep or shutdown. On the other hand there is source code available... 2. This looks interesting, but decription is not 100% clear for me. I need to sit and make some testing. 4. BIG THANX for this ideas! –  Juras.pl Mar 6 '13 at 12:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.