CeRunAppAtTime (coredll)
Last changed: jon_schweitzer@hotmail.com-207.16.196.52

.
Summary
This function prompts the system to start running a specified application at a specified time.

C# Signature:

[DllImport("coredll.dll", EntryPoint="CeRunAppAtTime", SetLastError=true)]  
private static extern bool CeRunAppAtTime(string pwszAppName, byte[] lpTime);

VB Signature:

    Public Declare Function CeRunAppAtTime Lib "coredll" _
       (ByVal AppName As String, ByRef ExecTime As SYSTEMTIME) As Boolean

User-Defined Types (VB):

    Public Structure SYSTEMTIME
    Dim wYear As Short
    Dim wMonth As Short
    Dim wDayOfWeek As Short
    Dim wDay As Short
    Dim wHour As Short
    Dim wMinute As Short
    Dim wSecond As Short
    Dim wMilliseconds As Short
    End Structure

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

In VB, function will return "true" if successful when adding app to run. However, it returns a "false" when cancelling the app even though the event is successfully cancelled. I'm guessing this is due to the systemtime structure being passed by reference and in this case references nothing. See sample code below. (VB .NET CF)

Tips & Tricks:

While this wakes the device, the screen remains powered off. Combine with SetSystemPowerState truly wake up everything.

VB Sample Code:

    Dim app As String = "\path\testapp.exe"
    Dim NewDate As Date
    Dim wakeuptime As SYSTEMTIME

    Private Sub scheduleapp
    NewDate = Now
    'take the current time and date and add some hours, minutes, and seconds
    NewDate = DateAdd(DateInterval.Hour, 5, NewDate)
    NewDate = DateAdd(DateInterval.Minute, 10, NewDate)
    NewDate = DateAdd(DateInterval.Second, 30, NewDate)

    'populate systemtime structure with our new date
    With wakeuptime
        .wDay = NewDate.Day
        .wDayOfWeek = NewDate.DayOfWeek
        .wHour = NewDate.Hour
        .wMilliseconds = NewDate.Millisecond
        .wMinute = NewDate.Minute
        .wMonth = NewDate.Month
        .wSecond = NewDate.Second
        .wYear = NewDate.Year
    End With

    If CeRunAppAtTime(app, WakeUpTime) Then
        MessageBox.Show("App successfully scheduled to run")
    Else
        MessageBox.Show("Call to CeRunAppAtTime failed")
    End If
    End Sub

    Private Sub cancelschedule
       CeRunAppAtTime(app, Nothing)
    End Sub

Documentation