To All, After a bit of Digging Around I found these Functions to Synchronise the time with any other machine on the Network. It works great so I thought that I would Share the solution with all of you out there! Enjoy
PS Thanks for the Help from All of you
Dave Crozier DaveC At Replacement-Software .DO.T co.uk
* Example Progeam and Function * to Sync Network Time with any other Machine * ...on the Network =SyncTime("\\NTSERVER") * return
************************************** ** SyncTime(<<cServer>>) ** Function to Retrieve the Time from a Remote Server ** Function SyncTime() Lparameter tcServer Local lcServer, llRetVal Local lnYear, lnMonth, lnDayOfWeek, lnDay, lnHour, lnMinute, lnSecond, lnMillisecond
Declare Integer NetRemoteTOD In netapi32 String @, Integer @ Declare RtlMoveMemory In WIN32API As CopyMemory String @, Integer, Integer Declare Integer SetSystemTime In kernel32 String At
llRetVal = .DO.T F. If Vartype(tcServer)="C" .And. .Not. Empty(tcServer) lcServer = Upper(Alltrim(tcServer))
lcServer = Strconv(Strconv(tcServer, 1), 5)+Chr(0) lnPtr = 0 lcTimeOfDay = Replicate(Chr(0), 48) lcSystemTime = Space(0) nRes = NetRemoteTOD(@lcServer,@lnPtr) If nRes=0 = CopyMemory(@lcTimeOfDay,@lnPtr,48)
lnYear = DWORDTONUM(Substr(lcTimeOfDay, 41, 4)) lnMonth = DWORDTONUM(Substr(lcTimeOfDay, 37, 4)) lnDayOfWeek = DWORDTONUM(Substr(lcTimeOfDay, 45, 4)) lnDay = DWORDTONUM(Substr(lcTimeOfDay, 33, 4)) lnHour = DWORDTONUM(Substr(lcTimeOfDay, 9, 4)) lnMinute = DWORDTONUM(Substr(lcTimeOfDay, 13, 4)) lnSecond = DWORDTONUM(Substr(lcTimeOfDay, 17, 4)) lcSystemTime = NUMTOWORD(lnYear)+NUMTOWORD(lnMonth)+NUMTOWORD(lnDayOfWeek)+NUMTOWORD(ln Day)+NUMTOWORD(lnHour)+NUMTOWORD(lnMinute)+NUMTOWORD(lnSecond)+NUMTOWORD (0) nRes = SetSystemTime( At lcSystemTime) llRetVal = nRes<>0 Else Error 'Error code'+Transform(nRes)+" occurred attempting to retrieve remote time" llRetVal = .DO.T F. Endif Endif * Return llRetVal Endfunc
Function DWordToNum() Lparameter tcDWord Local LN0, LN1, LN2, LN3 LN0 = Asc(Substr(TCDWORD, 1, 1)) LN1 = Asc(Substr(TCDWORD, 2, 1))*256 LN2 = Asc(Substr(TCDWORD, 3, 1))*(65536) LN3 = Asc(Substr(TCDWORD, 4, 1))*(16777216) Return LN3+LN2+LN1+LN0 Endfunc
Function NumToWord Lparameter tnNum lcResult = Chr(0)+Chr(0) If tnNum<(32767) lcResult = Chr(Mod(TNNUM, 256))+Chr(Int(TNNUM/256)) Else * Endif Return LCRESULT * Endfunc
©2003 Dave Crozier |