用 NetRemoteTOD() API 函数可以从 Server 2003系统取到系统时间吗?
时间:2007-03-09
来源:互联网
大家好!
现在要取得局域网某一台 Windows Server 2003系统机器的系统时间,在 VB6.0 下用
NetRemoteTOD() API 函数可以取到吗?
目前我这边没有这个测试条件,在xp系统下是可以的,看看各位谁有这个测试条件,谢谢了!
代码如下:
-------------------------------------
Option Explicit
Private Declare Function NetRemoteTOD Lib "Netapi32.dll " (tServer As Any, pBuffer As Long) As Long
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Declare Function NetApiBufferFree Lib "Netapi32.dll " (ByVal lpBuffer As Long) As Long
Private 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
Private Declare Sub CopyMemory Lib "kernel32 " Alias "RtlMoveMemory " ( _
Destination As Any, Source As Any, ByVal Length As Long)
Public Function getRemoteTOD(ByVal strServer As String) As Date
Dim result As Date
Dim lRet As Long
Dim tod As TIME_OF_DAY_INFO
Dim lpbuff As Long
Dim tServer() As Byte
tServer = strServer & vbNullChar
lRet = NetRemoteTOD(tServer(0), lpbuff)
If lRet = 0 Then
CopyMemory tod, ByVal lpbuff, Len(tod)
NetApiBufferFree lpbuff
result = DateSerial(tod.tod_year, tod.tod_month, tod.tod_day) + _
TimeSerial(tod.tod_hours, tod.tod_mins - tod.tod_timezone, tod.tod_secs)
getRemoteTOD = result
Else
Err.Raise Number:=vbObjectError + 1001, _
Description:= "cannot get remote TOD "
End If
End Function
Private Sub Form_Load()
Dim d As Date
d = getRemoteTOD( "192.168.186.110 ")
MsgBox d
End Sub
------------------------------
现在要取得局域网某一台 Windows Server 2003系统机器的系统时间,在 VB6.0 下用
NetRemoteTOD() API 函数可以取到吗?
目前我这边没有这个测试条件,在xp系统下是可以的,看看各位谁有这个测试条件,谢谢了!
代码如下:
-------------------------------------
Option Explicit
Private Declare Function NetRemoteTOD Lib "Netapi32.dll " (tServer As Any, pBuffer As Long) As Long
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Declare Function NetApiBufferFree Lib "Netapi32.dll " (ByVal lpBuffer As Long) As Long
Private 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
Private Declare Sub CopyMemory Lib "kernel32 " Alias "RtlMoveMemory " ( _
Destination As Any, Source As Any, ByVal Length As Long)
Public Function getRemoteTOD(ByVal strServer As String) As Date
Dim result As Date
Dim lRet As Long
Dim tod As TIME_OF_DAY_INFO
Dim lpbuff As Long
Dim tServer() As Byte
tServer = strServer & vbNullChar
lRet = NetRemoteTOD(tServer(0), lpbuff)
If lRet = 0 Then
CopyMemory tod, ByVal lpbuff, Len(tod)
NetApiBufferFree lpbuff
result = DateSerial(tod.tod_year, tod.tod_month, tod.tod_day) + _
TimeSerial(tod.tod_hours, tod.tod_mins - tod.tod_timezone, tod.tod_secs)
getRemoteTOD = result
Else
Err.Raise Number:=vbObjectError + 1001, _
Description:= "cannot get remote TOD "
End If
End Function
Private Sub Form_Load()
Dim d As Date
d = getRemoteTOD( "192.168.186.110 ")
MsgBox d
End Sub
------------------------------
作者: crazypc 发布时间: 2007-03-09
我试过了,2003用IP地址不行
作者: xunfei_xunfei 发布时间: 2007-04-19
用IP地址可以的阿!
作者: HackerJLY 发布时间: 2007-10-26
复制到 vb里 运行 报 实时错误
作者: parv2 发布时间: 2011-10-25
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28