PEGAR HORA DO SERVIDOR
Alguepem pode me ajudar com este problema:
Tenho dois programs um rodando no servidor e outro em um cliente, só que a máquina cliente precisa registrar a entrada e saida de funcionários , mas não pode se basear na hora da maquina cliente e sim basear na data e hora da maquina servidor, tem como eu pegar a data e hora do servidor ????
Grato pela ajuda
Tenho dois programs um rodando no servidor e outro em um cliente, só que a máquina cliente precisa registrar a entrada e saida de funcionários , mas não pode se basear na hora da maquina cliente e sim basear na data e hora da maquina servidor, tem como eu pegar a data e hora do servidor ????
Grato pela ajuda
Buscar data e hora do servidor
Para chamar: Data = ServerTime("\\NomedaMaquina") ou Data = ServerTime("NomedaMaquina").
'Coloque isso 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
Te +[S56]
Para chamar: Data = ServerTime("\\NomedaMaquina") ou Data = ServerTime("NomedaMaquina").
'Coloque isso 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
Te +[S56]
Tópico encerrado , respostas não são mais permitidas