VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get Windows NT Server Time

by Matthew Ruffell (3 Submissions)
Category: Windows System Services
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (18 Votes)

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

Inputs
ServerName [string] = name of target server.
Assumes
Requires Windows NT.
Code 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

Rate Get Windows NT Server Time

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

Download this snippet    Add to My Saved Code

Get Windows NT Server Time Comments

No comments have been posted about Get Windows NT Server Time. Why not be the first to post a comment about Get Windows NT Server Time.

Post your comment

Subject:
Message:
0/1000 characters