解决方案 »
- VB6.0 有关post的取返回值
- 在vb中,怎样 确定text中的类型,
- PostMessage问题,求助各路大大
- 新手上路,请教vb的数据连接问题,
- 图片打印,急....
- 我想用vb实现ping一组ip地址,通过结果来判断网络状态,应该怎么做?
- 用Keybd_Event怎么样输出美元符?
- 急求:vb中spread中设置两列行头 如何让两列行头 颜色不一样
- 我现在在写工资系统,但不知道如何写,谁有完整的工资系统源????给我一份[email protected]
- to bucher:help me!我找了一个多小时也没找到crystal report8
- 用MMControl播放avi文件的问题?
- 怎样建立一个连接,拨通对方的电脑(用猫)
我用工作站的VB编程序做的每个操作,希望不读取本机日期时间,想读取服务器时间!
听说VB中有个函数能实现,不知道哪位专家了解?
'
'执行命令:
'net time "\\OhterComputerName" /set /yes 可以保证名称为OhterComputerName 的计算机与本机时间同步。
'Public Sub SyncTime()
'Dim thecomp As String
'Dim theshell As String
'thecomp = "\\computername"
'theshell = "net time " & Chr(34) & thecomp & Chr(34) & " /set /yes"
'x = Shell(theshell)
'End Sub
Private Function SyncTime(ByVal ServerName As String) As BooleanDim theshell As String
On Error GoTo Error_SyncTime
theshell = "net time " & Chr(34) & "\\" & ServerName & Chr(34) & " /set /yes"
x = Shell(theshell)
SyncTime = True
Exit FunctionError_SyncTime:
SyncTime = FalseEnd FunctionPrivate Sub cmdSet_Click() If SyncTime(Trim(txtSetTime.Text)) Then MsgBox "同步时间成功!"End Sub
Dim rs As New ADODB.Recordset
on error goto err
Set rs = "select getdate() as dd", CN, adOpenKeyset, adLockOptimistic, adCmdText
If rs.RecordCount > 0 Then Gettime = rs.Fields(0).Value
err:
If Not rs Is Nothing Then
If rs.State <> adStateClosed Then
rs.Close
Set rs = Nothing
Else
Set rs = Nothing
End If
End If
End Function
那可是我要用MSGBOX显示服务器的时间如何做?那个变量C反回的是ID号呀.
不想连SQL呢?连SQL的李大虾已经指点过了,好使.
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 TypePrivate 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 TypePrivate Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As LongPrivate 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 Command1_Click()
Dim d As Date
d = getRemoteTOD("\\机器名称")
MsgBox d
End Sub
You are real daxia!!!!!!