1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
Option Explicit
Private Declare Function NetRemoteTOD Lib "NETAPI32" (ByVal server As Any, pBuffer As Long) As Long
Private Declare Function NetApiBufferFree Lib "NETAPI32" (ByVal pBuffer As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal length As Long)
Private Type TimeOfDayInfo
elapsedt As Long: msecs As Long: hours As Long: mins As Long
secs As Long: hunds As Long: timezone As Long: tinterval As Long
Day As Long: month As Long: year As Long: weekday As Long
End Type
'getDateTimeServer("freebox")
Public Function getDateTimeServer(ByVal serverName As String) As Date
Dim t As TimeOfDayInfo, lPtr As Long
serverName = StrConv("\\" & serverName & vbNullChar, vbUnicode)
If NetRemoteTOD(serverName, lPtr) = 0 Then
CopyMemory t, ByVal lPtr, Len(t): NetApiBufferFree lPtr
getDateTimeServer = DateSerial(t.year, t.month, t.Day) + _
TimeSerial(t.hours, t.mins - t.timezone, t.secs)
End If
End Function |
Partager