Windows NT:指定したサーバーの時間を取得する方法 Hit Counter

対象バージョン : 97, 2000, 2002, 2003
最終更新日 : 2016/09/18 (オリジナル作成日 : 1998/12/21)


概 要 

Windows NT のクライアントから、指定したサーバーの日付・時間を取得する方法です。

 

解 説

宣言
Declare Function NetRemoteTOD Lib "Netapi32.dll" _
    (UncServerName As Any, BufferPtr As Long) As Long

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)

Type TIME_OF_DAY_INFO
    tod_elapsedt As Long
    tod_msecs As Long
    tod_hours As Long
    tod_mins As Long
    tod_secs As Long
    tod_hunds As Long
    tod_timezone As Long
    tod_tinterval As Long
    tod_day As Long
    tod_month As Long
    tod_year As Long
    tod_weekday As Long
End Type

プロシージャ
Public Function GetServerDateTime(argServerName) As Date
Dim abytServerName() As Byte
Dim ptrTOD As Long
Dim stuTOD As TIME_OF_DAY_INFO
Dim ret As Long

abytServerName = argServerName & vbNullChar
ret = NetRemoteTOD(abytServerName(0), ptrTOD)
If ret <> 0 Then
    MsgBox "Server Not Found"
    Exit Function
End If

CopyMemory stuTOD, ptrTOD, Len(stuTOD)
GetServerDateTime = DateSerial(stuTOD.tod_year, stuTOD.tod_month, stuTOD.tod_day) + _
    TimeSerial(stuTOD.tod_hours, stuTOD.tod_mins - stuTOD.tod_timezone, stuTOD.tod_secs)
End Function
 
呼び出し例
Dim dtSvDateTime As Date
dtSvDateTime = GetServerDateTime("サーバー名")

 

補 足

 

改訂履歴


目次へ戻る