VB and VBA Users Source Code: Get Date/Time of a Network machine
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Get Date/Time of a Network machine
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, January 01, 2001
Hits:
575
Category:
Networks
Article:
To return the date and time on a remote machine use the following routine: Option Explicit Private Declare Function NetRemoteTOD Lib "netapi32.dll" (yServer As Any, pBuffer As Long) As Long Private Declare Function NetApiBufferFree Lib "netapi32.dll" (ByVal pBuffer As Long) As Long Private Declare Sub CopyMem Lib "kernel32.dll" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long) Private Type TIME_OF_DAY_INFO telapsed As Long tmsecs As Long thours As Long tmins As Long tsecs As Long thunds As Long ttimezone As Long ttinterval As Long tday As Long tmonth As Long tyear As Long tweekday As Long End Type 'Purpose : Return the time of a remote or local machine 'Inputs : [sServerName] The name of the machine to return the time of. ' If unspecified returns time on local machine. 'Outputs : The date and time on the specified machine 'Author : Andrew Baker 'Date : 01/01/2001 20:26 'Notes : 'Revisions : Function MachineTimeGet(Optional sServerName As String) As Date Dim tTime As TIME_OF_DAY_INFO Dim lRet As Long, lpBuffer As Long Dim abServer() As Byte If Len(sServerName) Then 'Check the syntax of the sServerName string If InStr(sServerName, "\\") = 1 Then abServer = sServerName & vbNullChar Else abServer = "\\" & sServerName & vbNullChar End If lRet = NetRemoteTOD(abServer(0), lpBuffer) Else 'Local machine lRet = NetRemoteTOD(vbNullString, lpBuffer) End If CopyMem tTime, ByVal lpBuffer, Len(tTime) If lpBuffer Then Call NetApiBufferFree(lpBuffer) End If MachineTimeGet = DateSerial(tTime.tyear, tTime.tmonth, tTime.tday) + TimeSerial(tTime.thours, tTime.tmins - tTime.ttimezone, tTime.tsecs) End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder