? ServerTime("\\MiServidor")
*----------------------------------------------------
* FUNCTION ServerTime(tcServerName, tlUtcTime)
* Retorna la hora del servidor pasado como parametro
* PARAMETROS:
* tcServerName = Nombre del servidor
* tlUtcTime = .T. FH UTC - .F. FH Local
* RETORNO: FechaHora ó .Null. si hubo error
* USO: ? ServerTime("\\MiServidor")
*----------------------------------------------------
FUNCTION ServerTime(tcServerName, tlUtcTime)
IF PARAMETERS() < 2
tlUtcTime = .F.
ENDIF
DECLARE INTEGER NetRemoteTOD IN netapi32 ;
STRING @, INTEGER @
DECLARE INTEGER RtlMoveMemory IN win32api ;
STRING @outbuffer, ;
INTEGER inbuffer, ;
INTEGER bytes2copy
tdbuffout = REPLICATE(CHR(0), 48)
tdbuffin = 0
lcTryServerName = STRCONV(tcServerName, 5)
rc = NetRemoteTOD(@lcTryServerName, @tdbuffin)
IF rc = 0
=RtlMoveMemory(@tdbuffout, tdbuffin, 48)
ELSE
lcTryServerName = STRCONV("\\" + tcServerName, 5)
rc = NetRemoteTOD(@lcTryServerName, @tdbuffin)
IF rc = 0
=RtlMoveMemory(@tdbuffout, tdbuffin, 48)
ELSE
*-- Error con NetRemoteTOD()
RETURN .Null.
ENDIF
ENDIF
tod_month = str2long(SUBSTR(tdbuffout, 37, 4))
tod_day = str2long(SUBSTR(tdbuffout, 33, 4))
tod_year = str2long(SUBSTR(tdbuffout, 41, 4))
tod_hours = str2long(SUBSTR(tdbuffout, 9, 4))
tod_mins = str2long(SUBSTR(tdbuffout, 13, 4))
tod_secs = str2long(SUBSTR(tdbuffout, 17, 4))
tod_timezone = str2long(SUBSTR(tdbuffout, 25, 4)) * 60
serverdatetime = DATETIME(tod_year, tod_month, tod_day, ;
tod_hours, tod_mins, tod_secs)
IF tlUtcTime
tdServerTime = serverdatetime
ELSE
tdServerTime = serverdatetime - tod_timezone
ENDIF
RETURN tdServerTime
ENDFUNC
*----------------------------------------------------
FUNCTION str2long(tcLongStr)
LOCAL ln, lnRetVal
lnRetVal = 0
FOR ln = 0 TO 24 STEP 8
lnRetVal = lnRetVal + (ASC(tcLongStr) * (2^ln))
tcLongStr = RIGHT(tcLongStr, LEN(tcLongStr) - 1)
ENDFOR
RETURN lnRetVal
ENDFUNC
*----------------------------------------------------
Esta función fue tomada y ligeramente modificada del siguiente artículo de la Base de Conocimientos de Microsoft:-- Cómo utilizar la función NetRemoteTOD para obtener información de fecha y hora de un servidor --
http://support.microsoft.com/kb/249716
Luis María Guayán
No hay comentarios. :
Publicar un comentario
Los comentarios son moderados, por lo que pueden demorar varias horas para su publicación.