Página 1 de 1
Data e hora de outro PC na rede
Enviado: 07 Set 2020 15:11
por Eduardo Pinho
Boa tarde,
Alguém sabe como faz pra pegar a data e hora de outro PC na rede, pelo Harbour?
Consigo fazer uma gambiarra usando hb_run e net time, mas sempre quando uso "run" pipoca na tela uma janelinha preta meio tosca que nao consigo tirar.
Além do mais, imagino que talvez exista uma forma mais simples.
Pegar data e hora precisa da internet pelo harbour, tambem ajudaria.
Agradeço a ajuda.
Abcs
Data e hora de outro PC na rede
Enviado: 07 Set 2020 15:23
por Vlademiro
Aqui no fórum tem uma rotina do Alexandre Simões que esconde essa janela. Eu uso aqui nos meus fontes. Vou procurar aqui.
Data e hora de outro PC na rede
Enviado: 07 Set 2020 15:26
por Vlademiro
Código: Selecionar todos
#ifdef __PLATFORM__WINDOWS
/*
https://pctoledo.org/forum/viewtopic.php?f=57&t=23997&p=139078&hilit=run#p139078
*/
FUNCTION VLJ_ExecuteWin( cProgram, cParameter, lEspera )
LOCAL oShell, lOk := .T., nStyle, oErro
lEspera := Hb_DefaultValue(lEspera, .f.)
hb_Default( @cParameter , "" )
BEGIN SEQUENCE WITH __BreakBlock()
oShell := Win_OleCreateObject( "WScript.Shell" )
RECOVER
lOk := .F.
END
IF lOk
BEGIN SEQUENCE WITH __BreakBlock()
/*
intWindowStyle
Description
0 Hides the window and activates another window.
1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
2 Activates the window and displays it as a minimized window.
3 Activates the window and displays it as a maximized window.
4 Displays a window in its most recent size and position. The active window remains active.
5 Activates the window and displays it in its current size and position.
6 Minimizes the specified window and activates the next top-level window in the Z order.
7 Displays the window as a minimized window. The active window remains active.
8 Displays the window in its current state. The active window remains active.
9 Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
10 Sets the show-state based on the state of the program that started the application.
*/
nStyle := 0
oShell:Run("%comspec% /c " + cProgram + " " + cParameter, nStyle, lEspera)
RECOVER
Alert("Erro executando " + cProgram, "Erro")
lOk := .F.
END
oShell := Nil
ENDIF
RETURN lOk
#endif
Data e hora de outro PC na rede
Enviado: 09 Set 2020 21:01
por asimoes
Pegar data e hora da internet, horário de Brasília
Código: Selecionar todos
Alert( GetDataTimeNtp( "200.160.7.186" ) )
FUNCTION GetDataTimeNtp( cSeverNtp )
LOCAL cRet, cDateTime:= Alltrim( GETNTPDATE( cSeverNtp ) )
RETURN ( cDateTime )
#pragma BEGINDUMP
#include <hbapi.h>
#include <winsock.h>
#include <time.h>
#define MAXLEN 1024
HB_FUNC( GETNTPDATE )
{
char * hostname = ( char * ) hb_parc( 1 );
unsigned char msg[ 48 ] = { 010, 0, 0, 0, 0, 0, 0, 0, 0 }; // the packet we send
unsigned long buf[ MAXLEN ]; // the buffer we get back
struct sockaddr_in server_addr;
int s; // socket
WSADATA wsa;
struct timeval timeout;
fd_set fds;
time_t tmit;
WSAStartup( 0x101, &wsa );
s = socket( PF_INET, SOCK_DGRAM, getprotobyname( "udp" )->p_proto );
memset( &server_addr, 0, sizeof( server_addr ) );
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = inet_addr( hostname );
server_addr.sin_port = htons( 123 ); // ntp port
sendto( s, msg, sizeof( msg ), 0, ( struct sockaddr * ) &server_addr, sizeof( server_addr ) );
FD_ZERO( &fds );
FD_SET( s, &fds );
timeout.tv_sec = 10;
timeout.tv_usec = 0;
if( select( 0, &fds, NULL, NULL, &timeout ) )
{
recv( s, ( void * ) buf, sizeof( buf ), 0 );
tmit = ntohl( buf[ 10 ] );
tmit-= 2208988800U;
}
else
MessageBox( 0, "can't read from NTP server", "ok", 0 );
WSACleanup();
hb_retc( ctime( &tmit ) );
}
#pragma ENDDUMP
Data e hora de outro PC na rede
Enviado: 09 Set 2020 21:22
por asimoes
Se quiser pegar somente a hora:
cTime := SubStr( cDateTime, 12, 8 )
Data e hora de outro PC na rede
Enviado: 10 Set 2020 11:00
por asimoes
Data e hora de outro PC na rede
Enviado: 20 Set 2020 18:20
por Eduardo Pinho
Obrigado a todos.. Resolvi...