0

As a network admin, i try to keep all my computers in Sleep state during weeks (instead of shutdown) because i can then schedule a task to wake up the computers and so maintain/check them without any need to move physicaly to the other places.

But sometimes users just turn off the computers themself. So i am stuck and need to move there...

I would like to programaticaly (C#) : - detect/catch windows shutdown - execute kind of "shutdown -a" to cancel it. - plan a wake up in task scheduler - finaly, turn off computer using SLEEP and not shutdown.

Basicaly, my aim is to replace the Shutdown by Sleep so it will wake up on Scheduled task. Can anyone enlight me on some possibilities please?

what i have tried yet : Created a windows form with this:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (e.CloseReason == CloseReason.WindowsShutDown)
        {
            Process.Start("shutdown", "-a");
        }
    }

It throws an error because i cant run the cmd anymore since system is processing a shutdown.

user3916429
  • 562
  • 6
  • 25
  • 1
    This question may be helpful - http://stackoverflow.com/questions/2720125/how-cancel-shutdown-from-a-windows-service-c-sharp?rq=1 – Daniel Kelley May 18 '15 at 16:06
  • 1
    You should consider a [Wake-on-LAN](http://en.wikipedia.org/wiki/Wake-on-LAN) solution. – Thiago Sá May 18 '15 at 16:15
  • @DanielKelley The DLLIMPORT from your link is interresting, but i dont know where to use it, and how exactly, its hard on google to find any C# complete code example. – user3916429 May 18 '15 at 21:44

1 Answers1

2

how about just not letting your users shutdown the machine with window policies http://www.howtogeek.com/howto/7553/remove-shutdown-and-restart-buttons-in-windows-7/

CaldasGSM
  • 3,032
  • 16
  • 26