2

Hello I'm making a shutdown manager with Java and I'm done except for one thing, wake from sleep mode. I searched Google but I only found how to do it with task scheduler, I'm wondering if I can do it with Java?

This image is from task scheduler, I want to make something like this:

Jonny Henly
  • 4,023
  • 4
  • 26
  • 43
omar wael
  • 21
  • 2
  • There is something called Wake on LAN, where a datagram packet is sent to a specific computer in the network to wake it. You might be able to use this approach and send the datagram packet to your own PC via the local host loopback (IP: `127.0.0.1`). [Sending Wake on LAN packet from Android to PC](http://stackoverflow.com/questions/5682319/sending-wake-on-lan-packet-from-android-to-pc) - One of the answers has a Java implementation. – Jonny Henly Aug 19 '16 at 18:42
  • i know wake on lan but i don't need it i just want the computer wake from sleep after amount of time – omar wael Aug 19 '16 at 18:49
  • As far as I know there is no straight forward approach to do that. Perhaps using some Java code to make the mouse move will wake the computer. – Jonny Henly Aug 19 '16 at 18:53
  • so it is impossible to tell computer to wake after a xxx sec – omar wael Aug 19 '16 at 18:55
  • As far as I know, yes. – Jonny Henly Aug 19 '16 at 18:58
  • do i have another option to make something like this not with time but anything that can wake the computer – omar wael Aug 19 '16 at 19:04
  • As far as I know, no. – Jonny Henly Aug 19 '16 at 19:06
  • OK thanks but do you have any idea about this article http://www.codeguru.com/cpp/w-p/system/messagehandling/article.php/c6907/JavaC-PC-Standby-Detect-and-Prevent.htm – omar wael Aug 19 '16 at 19:11
  • That article states — *"I decided to use the Windows API to detect whether a standby request is made and refuse it."* — meaning that the computer would never go into sleep mode, so there would be no need to wake it. – Jonny Henly Aug 19 '16 at 19:23

1 Answers1

0

Java Native Interface may be what you want in order to wake the machine up from sleep. Try this article http://www.codeguru.com/cpp/w-p/system/messagehandling/article.php/c6907/JavaC-PC-Standby-Detect-and-Prevent.htm

If you are only interested in running a task after the machine wakes up, one thing you could do is loop check system current time vs system last current time.

Is it safe to say if you last current time is more than 10 seconds from the current time, the machine must have went into some kind of suspension?