[DllImport("coredll.dll", EntryPoint="CeRunAppAtTime", SetLastError=true)]
private static extern bool CeRunAppAtTime(string pwszAppName, byte[] lpTime);
Public Declare Function CeRunAppAtTime Lib "coredll" _
(ByVal AppName As String, ByRef ExecTime As SYSTEMTIME) As Boolean
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
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)
While this wakes the device, the screen may remain powered off. Combine with SetSystemPowerState truly wake up everything.
Also, if the app is making a call to wake itself back up, you can get the full path and appname with system.reflection.assembly. See code below for example.
Dim FullAppName As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase
Dim AppPathOnly As String = System.IO.Path.GetDirectoryName(FullAppName)
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(FullAppName, WakeUpTime) Then
MessageBox.Show("App successfully scheduled to run")
Else
MessageBox.Show("Call to CeRunAppAtTime failed")
End If
End Sub
Private Sub cancelschedule
'Make a call to cancel the scheduled app
Dim cancelapp as boolean = CeRunAppAtTime(FullAppName, Nothing)
End Sub