07 Set 2020 15:11
07 Set 2020 15:23
07 Set 2020 15:26
#ifdef __PLATFORM__WINDOWS
/*
http://www.pctoledo.com.br/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
09 Set 2020 21:01
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
09 Set 2020 21:22
10 Set 2020 11:00
20 Set 2020 18:20