I'm trying to use CeRunAppAtTime to kick my app into life for an overnight update. My test code ( below ) is attempting to start a simple " Hello Me" app. All I get back from the CeRunAppAtTime call is the result FALSE.
Am I going about this the correct way, and Is my VB SysTime structure compatible with what's needed.
Thanks
Public Declare Function CeRunAppAtTime Lib "Coredll.dll" Alias "CeRunAppAtTime" (ByVal appName As String, ByVal lpTime As SysTime) As Boolean
Public TargetTime As Date
Public Structure SysTime
Dim Year As Int16 Dim Month As Int16 Dim DayOfWeek As Int16 Dim Day As Int16 Dim Hour As Int16 Dim Minute As Int16 Dim Second As Int16 Dim Millesecond As Int16
End Structure
Public Sub SetSystemTime(ByRef t As SysTime, ByVal dt As DateTime)
t.year = CShort(dt.Year) t.month = CShort(dt.Month) t.day = CShort(dt.Day) t.dayOfWeek = CShort(dt.DayOfWeek) t.hour = CShort(dt.Hour) t.minute = CShort(dt.Minute) t.second = CShort(dt.Second) t.Millesecond = CShort(dt.Millisecond)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim t As SysTime ' Holds Target time in 'syetm' format Dim Result As Boolean ' result from call to CeRunAppAtTime
Label4.Text = "Time now is " & Now
TargetTime = DateAdd(DateInterval.Second, CInt(TextBox1.Text), Now)
Label3.Text = "Wake at " & TargetTime.ToString
Try SetSystemTime(t, TargetTime) ' Fill SysTime ( SystemTime) structure
Result = CeRunAppAtTime("Hello.exe", t) ' Run Hello app in device root
MsgBox("Result was " & Result.ToString) ' Report result
Catch ex As Exception MsgBox("CeRunAppAtTime() Error: " & ex.ToString) End Try
End Sub
|