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.