tags:

views:

74

answers:

2

Hi everyone,

I'm trying to add functionality in my program that will allow the user to wake their system from sleep at a set duration.

I've googled a lot about this and the examples online don't seem to work.

I've used WaitableTimer set the system to go to sleep but it doesn't seem to wake up.

Can anyone help me out here.

for code reference, I am using WPF

Thanks

A: 

Have you tried Wake On LAN (using MAC address):

namespace WakeOnLan
{
    class Program
    {
        static void Main(string[] args)
        {
            if(args.Length==1)
            {
                string bytes = args[0].Replace("-", "");
                long l = 0;
                if (bytes.Length != 12 || !long.TryParse(bytes.Substring(0, 6), NumberStyles.HexNumber, null, out l) || !long.TryParse(bytes.Substring(6), NumberStyles.HexNumber, null, out l))
                    Console.WriteLine("Invalid string");
                else
                {
                    try
                    {
                        WakeOnLan(bytes);
                        Console.WriteLine("Sent wake on lan");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
            }
            else
            {
                Console.WriteLine("WakeOnLan.exe <MAC Address>\r\nMAC address must be 6 bytes in hexadecimal format, optionally separated by hyphen.");
            }
        }

        private static void WakeOnLan(string bytesString)
        {
            List<byte> packet = new List<byte>();
            for (int i = 0; i < 6; i++)
            {
                packet.Add(byte.Parse(bytesString.Substring(i*2,2),NumberStyles.HexNumber));
            }

            byte[] mac = packet.ToArray();
            for (int i = 0; i < 15; i++)
            {
                packet.AddRange(mac);
            }
            for (int i = 0; i < 6; i++)
            {
                packet.Insert(0, 0xFF);
            }

            UdpClient client = new UdpClient();
            client.Connect(IPAddress.Broadcast, 7); //Any UDP port will work, but 7 is my lucky number ... 
            client.Send(packet.ToArray(), packet.Count); 
        }

    }
}
Aliostad
Aliostad
I was actually trying to stay away from Wake on LAN as most my users will be using a Wireless Adapter and this isn't obviously supported.
Sandeep Bansal
A: 

Is any other software able to wake your computer on schedule? You need to find out whether the problem is with your code or with your system configuration, and running someone else's software as a test is the easiest way.

You may need to enable "Wake on Timer" support in the BIOS.

What version of Windows are you using? Windows Vista and 7 come with some tools for enabling/disabling the ability of individual components to wake the system, in order to e.g. resolve problems when a very sensitive mouse unintentionally moves enough to wake the computer. You may need to enable wake support for the HPET or RTC components.

Ben Voigt
Hi, I am using Windows 7 x64 Ultimate, and I have enabled the use of wakeup timers in the power options settings but nothing happens, I could only find one other wake up timer but it doesn't seem to be opensource.
Sandeep Bansal
So you followed the instructions here: http://support.microsoft.com/kb/973454 ? The built-in Task Schedule can wake the computer, try this (instructions for Vista but will also work on 7): http://www.winvistaclub.com/t86.html
Ben Voigt