Re: Synchronize Date and Time with Delphi

[ DelphiLand FAQ ]

Posted by webmaster Guido on July 02, 2004 at 19:26:13:

In Reply to: Re: Date and Time posted by giovanni caramia on June 30, 2004 at 20:24:10:

: : I want to be able to syncroniz my workstation's date and time with that of my server's date and time. how do i go about it?

: I solved:

: procedure TForm1.Button1Click(Sender: TObject);
: var b : string ;
: begin
: b := ' time \\ServerName /set /y';
: ShellExecute(Handle, 'open','net',pchar(b), nil, SW_SHOWNORMAL);
: end;

: Giovanni caramia

Some notes by webmaster Guido:

uses Microsoft's NET utility for synchronizing a workstation's date and time with the network time server. Just try this NET command on the DOS-prompt, or through the "Run" option of Windows' start-menu.

The meaning of the parameters:
"TIMEHOST" is the name of the network's time server, the computer that is serving the time.
"/SET" adjusts the date and time of the local system-clock and asks for confirmation.
"/Y" provides automatic confirmation (also /YES will work).

If it works, you can code it into your Delphi application, using the "Shellexecute" function to start the NET utility, as shown in the friendly post from Giovanni (see above).

Additional notes:
1. In order for the compiler to find ShellExecute, you have to add SHELLAPI to the USES clause of the unit.
2. If you don't know the name of the time server, try this on the DOS prompt, to list the time server(s) for your domain:
NET TIME /querysntp
3. Doesn't work? Then maybe try this to synchronize the workstation's clock with that of the domain:

[ DelphiLand FAQ ]