Hola invitado         02 Sep, 2010 - 04:28
Menú principal
 
Ads
 
Patrocinadores
 
Anuncios
 
© 2009 PortalFox
Fecha y hora de un Servidor lecturas 5686
 Enviado por Luis María Guayán en Lunes, 02 Mayo, 2005
API Con esta función podemos tomar la fecha y hora de un servidor Windows NT o superior, desde Visual FoxPro, con funciones de la API de Windows.

Fecha y hora de un Servidor

Luis María Guayán Por Luis María Guayán, Tucumán, Argentina



? 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
 Versión imprimible  
Fecha y hora de un Servidor | Entrar/Crear una cuenta | 1 Comentario
Los comentarios son propiedad de sus respectivos autores.
No somos responsables de su contenido.

Fecha y hora de un Servidor


por LUISRO en 02 May, 2005 - 11:17
(Información del usuario  | Enviar un mensaje http://)
Exelente. Creo que da solucion a largas horas de pruebas con diferentes metodos. De todos, me quedo con este.




Todas las marcas y los logos utilizados en este sitio son propiedad de sus respectivos dueños.
Los artículos, noticias y comentarios son propiedad y responsabilidad de sus respectivos autores.
Copyright © 2000-2010 PortalFox. Todos los derechos reservados.