Option Explicit
Option Compare Text
[color=green]' Date/Time structure for the API calls[/color]
Private Type udtTimeOfDayInfo
lngElapsedTime As Long
lngMilliSeconds As Long
lngHour As Long
lngMin As Long
lngSecond As Long
lngHundreds As Long
lngTimeZone As Long
lngInterval As Long
lngDay As Long
lngMonth As Long
lngYear As Long
lngWeekday As Long
End Type
[color=green]' From the http://allapi.mentalis.org/apilist/NetRemoteTOD.shtml[/color]
Private Declare Function NetRemoteTOD Lib "NETAPI32.DLL" (ByVal lngServer As Long, _
ByRef lngBufPtr As Long) As Long
Private Declare Function NetApiBufferFree Lib "NETAPI32.DLL" (ByVal lngBufPtr As Long) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" (ByRef pDest As Any, _
ByVal pSrc As Any, _
ByVal lngByteLen As Long)
[color=green]' Server name constant, insert as required to suit your system[/color]
Private Const conServerName As String = ""
Sub TestTheCall()
MsgBox GetTimeFromServer(, "Local")
MsgBox GetTimeFromServer(, "GMT")
MsgBox GetTimeFromServer(conServerName, "Local")
MsgBox GetTimeFromServer(conServerName, "GMT")
End Sub
Public Function GetTimeFromServer(Optional ByVal strServer As String = vbNullString, _
Optional ByVal strLocation As String = "Local") As Variant
[color=green]' Function: Gets the time of day from the specified server
' Original example by Chaz Branham (bran2@zande.com)
' Modified by Ken Henderson (1/2002) & ChrisO (6/2003)
'
' Modified by ChrisO 4/2011 (Work in progress.)
' udtTODI.lngTimeZone is the local machine daylight saving time offset from GMT.
' To get Local machine time, add the lngTimeZone offset.
' To get GMT time, do NOT add lngTimeZone.[/color]
Dim udtTODI As udtTimeOfDayInfo
Dim vntReturn As Variant
Dim lngBufPtr As Long
If NetRemoteTOD(StrPtr(strServer), lngBufPtr) = 0 Then
RtlMoveMemory udtTODI, lngBufPtr, Len(udtTODI)
With udtTODI
Select Case strLocation
Case "Local"
[color=green]' Raw GMT time + adjust for local time.[/color]
vntReturn = DateSerial(.lngYear, .lngMonth, .lngDay) + _
TimeSerial(.lngHour, .lngMin, .lngSecond) _
- (.lngTimeZone / 1440)
Case "GMT"
[color=green]' Raw GMT time, no adjust.[/color]
vntReturn = DateSerial(.lngYear, .lngMonth, .lngDay) + _
TimeSerial(.lngHour, .lngMin, .lngSecond)
Case Else
MsgBox "Only arguments allowed are 'Server name' and 'Local' or 'GMT' location." & _
vbNewLine & vbNewLine & _
"Please fix.", vbCritical + vbOKOnly, "No can do."
vntReturn = "Twelfth of never."
End Select
End With
NetApiBufferFree lngBufPtr
GetTimeFromServer = vntReturn
End If
End Function