Tools Links Login

Get Windows NT Server Time

Returns the time of day from a Windows NT workstation or server. Accounts for time zones. Requires Windows NT.

Original Author: Matthew Ruffell

Inputs

ServerName [string] = name of target server.

Assumptions

Requires Windows NT.

Returns

Return the time of day.

Side Effects

Noen.

API Declarations

Private Type TIME_OF_DAY
t_elapsedt As Long
t_msecs As Long
t_hours As Long
t_mins As Long
t_secs As Long
t_hunds As Long
t_timezone As Long
t_tinterval As Long
t_day As Long
t_month As Long
t_year As Long
t_weekday As Long
End Type
Private Declare Function NetRemoteTOD Lib "netapi32.dll" (ByVal server As String, buffer As Any) As Long
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function NetApiBufferFree Lib "netapi32.dll" (ByVal Ptr As Long) As Long

Code

Public Function Get_ServerTime(ByVal strServerName As String) As String
  
  Dim lngBuffer As Long
  Dim strServer As String
  Dim lngNet32ApiReturnCode As Long
  Dim days As Date
  Dim TOD As TIME_OF_DAY
  
  On Error Resume Next
  
  '// Get server time
  strServer = StrConv(strServerName, vbUnicode) '// Convert the server name to unicode
  lngNet32ApiReturnCode = NetRemoteTOD(strServer, lngBuffer)
  If lngNet32ApiReturnCode = 0 Then
    CopyMem TOD, ByVal lngBuffer, Len(TOD)
    days = DateSerial(70, 1, 1) + (TOD.t_elapsedt / 60 / 60 / 24) '// Convert the elapsed time since 1/1/70 to a date
    days = days - (TOD.t_timezone / 60 / 24) '// Adjust for TimeZone differences
    Get_ServerTime = days
  End If
  
  '// Free pointers from memory
  Call NetApiBufferFree(lngBuffer)
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 94 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.