Thursday, September 21, 2006

Setting Time and Date on the Device From the Desktop

An interesting problem that has come up several times is how to set the time and date on the device via RAPI (which also includes the Srego CE ToolPack ActiveX control). There may be a simple solution to this that I don't know, but I have not found one so far. It is very simple to write an app for the device to set the time and date, and then call the app via RAPI with the Parameters. The sample set time app is available here; the eVC++ 4.0 source code is available on request.

The sample code below will check to see if the ceSetTime.exe is already on the device, if not it will push it to the device. Then the time and date from the desktop is used as parameters when starting the ceSetTime app on the device. One problem with this approach is the security prompt from Windows Mobile 5.0.


VB 6.0 Sample Code

' Check to see if ceSetTime.exe utility is on the device

If Not SregoCETPx1.VerifyFile("\windows\ceSetTime.exe") Then

' if ceSetTime.exe exe is not on the device, then copy it to the device
' The ceSetTime.exe should be in the same path as the main app in this
' example; however, it could be anywhere as long as you know the location

If Not SregoCETPx1.PushFile(App.Path + "\ceSetTime.exe", _

"\windows", False) Then

Debug.Print "unable to copy utility to device"

End If

End If

' Build the command line for the ceSetTime.exe utility
'
' ceSetTime
'
' the argument will be a valid integer value or and asterisk (*) to
' keep the devices original setting

Dim timeStr As String

timeStr = Str(Year(Date)) + " " + Str(Month(Date)) + " " + _

Str(Day(Date)) + " " + _
Str(Hour(Time)) + " " + Str(0) + " " + Str(Second(Time))


' Run the ceSetTime.exe on the device with the

' desktop's time as a parameter

SregoCETPx1.StartApplicationEx "\windows\ceSetTime.exe", timeStr

' Delete ceSetTime.exe from device

SregoCETPx1.DeleteFile App.Path + "\ceSetTime.exe"

No comments: