Tengo que obtener la fecha y la hora de un servidor remoto mediante codigo de visual basic.
Gracias por vuestras respuestas.
| ||||
revisa si esto te sirve (tomado de www.allapi.net) 'Example by Chaz Branham ([email protected]) 'This example show's you how to use the api 'call NetRemoteTOD in vb. It also has some 'other code where it updates your system time 'with the server's time. Very easy to follow 'and short and to the point. Option Explicit Private Declare Function NetRemoteTOD Lib "Netapi32.dll" (yServer As Any, pBuffer As Long) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long) Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal lpBuffer As Long) As Long Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long Private Type TIME_OF_DAY_INFO tod_elapsedt As Long tod_msecs As Long tod_hours As Long tod_mins As Long tod_secs As Long tod_hunds As Long tod_timezone As Long tod_tinterval As Long tod_day As Long tod_month As Long tod_year As Long tod_weekday As Long End Type Private Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type Private Sub Form_Load() Dim TimeMemoryBuffer As Long, result As Long, TOD As TIME_OF_DAY_INFO, Servername() As Byte Dim sys_sync As SYSTEMTIME ' Note Servername has to be an Array Byte for this to work properly! ' This servername must be a valid Windows Network server; if it doesn't ' exist, your application might crash! Servername = "\\Columbus-fs02" & vbNullChar result = NetRemoteTOD(Servername(0), TimeMemoryBuffer) CopyMemory TOD, ByVal (TimeMemoryBuffer), LenB(TOD) Me.AutoRedraw = True Me.Print "Day:" & TOD.tod_day Me.Print "Month:" & TOD.tod_month Me.Print "Year:" & TOD.tod_year Me.Print "Hours:" & TOD.tod_hours Me.Print "Minutes:" & TOD.tod_mins Me.Print "Seconds:" & TOD.tod_secs Call NetApiBufferFree(TimeMemoryBuffer) With sys_sync .wHour = TOD.tod_hours .wMinute = TOD.tod_mins .wSecond = TOD.tod_secs .wDay = TOD.tod_day .wMonth = TOD.tod_month .wYear = TOD.tod_year End With SetSystemTime sys_sync End Sub |