VB icon

Get Windows NT Server Time

Email
Submitted on: 1/3/2015 3:12:00 PM
By: Matthew Ruffell (from psc cd)  
Level: Not Given
User Rating: By 18 Users
Compatibility: VB 5.0, VB 6.0
Views: 574
 
     Returns the time of day from a Windows NT workstation or server. Accounts for time zones. Requires Windows NT.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Get Windows NT Server Time
'**************************************
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:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Get Windows NT Server Time
' Description:Returns the time of day from a Windows NT workstation or server. Accounts for time zones. Requires Windows NT.
' By: Matthew Ruffell (from psc cd)
'
' Inputs:ServerName [string] = name of target server.
'
' Returns:Return the time of day.
'
' Assumes:Requires Windows NT.
'
' Side Effects:Noen.
'**************************************

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


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.