stanac / shutdown

Timed shut down of your Windows PC
http://stanac.github.io/shutdown/
MIT License
12 stars 5 forks source link

[Request] Options #3

Closed Gelo3D closed 7 years ago

Gelo3D commented 7 years ago

Add new timing option :

locked pc - example - if You download something and u wonna protect Your pc u need to example 10/15 minute to lock Your computer

sleep pc - sleep pc is best option if u need fast rest Your pc to work.

stanac commented 7 years ago

Hi @Gelo3D sleep option does make sense, but I would disagree on lock, What is the use case of delaying lock operation? From your comment about lock... I don't see what is stopping your PC from downloading something while PC is locked?

Gelo3D commented 7 years ago

Dat was just only example. Just do very simple lock pc option. Sry bro for my english, that was a reasion for had trouble understanding.

stanac commented 7 years ago

NP, I will investigate sleep mode

zvonimirr commented 7 years ago

Is this still open and being considered? I would like to contribute.

stanac commented 7 years ago

Hello @rudinskizvonimir ticket is still open. Contribution would be welcome. Thank you.

zvonimirr commented 7 years ago

Great, I'll start as soon as I can

theogjpeezy commented 7 years ago

I have a solution for this. The existing shutdown command in the project does not actually support a sleep. There is a way to use rundll32.exe to set the power profile to force sleep, however, if the OS has hibernation enabled then it will cause the machine to go into hibernation, not sleep. Described Here The solution seems to be using PsShutdown in the PsTools Suite. After including this in the project it works as expected. To minimize scope, I have only implemented using PsShutdown for sleep, all other features still utilize shutdown.exe. The only (minor) drawback is that the user will have to agree to the SysInternals EULA when they select sleep for the first time. After accepting the EULA, they will not see this dialog box again. If this approach sounds appropriate, I can submit a Pull Request for review.

stanac commented 7 years ago

Did you try Application.SetSuspendState method?

Simple test on my laptop showed that both hibernate (already implemented) and sleep (also called suspend, with mentioned method) worked.

We don't want to complicate and introduce unneeded dependencies. We should use SetSuspendState and if it's not working on some PCs we can leave a comment on the web why it's not working and that it won't be handled for all edge cases.

Here is the code I've tried:

System.Windows.Forms.Application.SetSuspendState(
    System.Windows.Forms.PowerState.Suspend,
    force: false, 
    disableWakeEvent: false);

We just need "force" option to be set in there.

stanac commented 7 years ago

@rudinskizvonimir please let me know what you think about my previous comment.

theogjpeezy commented 7 years ago

@stanac I'll give it a go. I'll report back later today.

theogjpeezy commented 7 years ago

@stanac The SetSuspendedState method worked without issue. I have reworked it so that it uses this. If it is okay, I'd be ready to make a pull request at this time.

stanac commented 7 years ago

@theogjpeezy please create pull request. Thanks

stanac commented 7 years ago

implemented in #4