|
|
|
|
|
Dicas
|
|
Visual Basic (Redes/Comunicações)
|
|
|
Título da Dica: Pegar data e hora de um servidor
|
|
|
|
Postada em 14/8/2000 por Webmaster
webmaster@vbweb.com.br
'OBS: Função disponível apenas para plataforma NT
'Em um botão:
Private Sub Command1_Click()
MsgBox ServerTime("NomedaMaquina")
End Sub
'Em um módulo:
Private Declare Function NetRemoteTOD Lib _ "NETAPI32.DLL" (ByVal server As _ String, buffer As Any) As Long Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" (hpvDest As _ Any, hpvSource As Any, ByVal cbCopy _ As Long) Private Declare Function NetApiBufferFree Lib _ "NETAPI32.DLL" (buffer As Any) As Long
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
Public Function ServerTime(ByVal pServerName _ As String) As Variant Dim t As TIME_OF_DAY Dim tPtr As Long Dim Result As Long Dim szServer As String Dim ServDate As Date If Left(pServerName, 2) = "\\" Then szServer = StrConv(pServerName,vbUnicode) Else szServer = StrConv("\\" & pServerName, _ vbUnicode) End If Result = NetRemoteTOD(szServer, tPtr) If Result = 0 Then Call CopyMemory(t, ByVal tPtr, Len(t)) ServDate = DateSerial(70, 1, 1) + _ (t.t_elapsedt / 60 / 60 / 24) ServDate = ServDate - (t.t_timezone / 60 / 24) NetApiBufferFree (tPtr) ServerTime = ServDate Else 'erro End If End Function
|
|
|
|
|