The Windows time service seems to randomly use either the primary or
secondary network for communication with the network time server, causing the
time synchronization to fail when it uses the IP address for the 'local'
network.
So my question is twofold:
1. Is there a way to diagnose this problem? I don't see any event in
eventviewer when the synchronization failed.
2. How can I force the time service to use a specific IP address when there
are multiple IP addresses configured?
Thanks.
1. To diagnose w32time issues, read this:
http://support.microsoft.com/kb/816043
2. Although the ntp implementation seems to scan all available addresses, it
sometimes fails on our systems. Calling the synchronization function in
w32time.dll directly providing the proper IP address fixes it (This is the
function called by the timedate applet and the w32tm command line utility).
Here is the function signature:
/*-------------------------------------------------------------------------*
* Force a time sync with a network time server
*
* Parameters:
* - pwszComputer: the computer to sync the clock for,
* NULL to sync the local computer.
* - blocking: 0: to perform an asynchronous call (always returns 'ok')
* 1: perform a blocking call
* - flags: probably a bitwise combination. Following combinations are tested:
* 0x03: just resync
* 0x06: redetect the network configuration and rediscover network
sources, than resync
*
* return value:
* 0: update successful
* 1: The computer did not resync because no time data was available
* 2: The computer did not resync because only stale time data was
available
* 3: The computer did not resync because the time service was shutting
down
* 4: The computer did not resync because the required time change was
too big
* any other value: standard Windows Error
*
*-------------------------------------------------------------------------*/
typedef int ( __stdcall* W32TimeSyncNow)( const wchar_t *pwszComputer,
unsigned int blocking, unsigned int flags);
Please help me..
i didn't get any grip to start my job.. :(
As far as I know, there is no library nor header file to access the Windows
Time functions through an API. That leaves you with three options:
- spawn the w32tm.exe command that you need. W32tm.exe is a wrapper to
access the functions in w32time.dll
- reverse-engineer the functions provided by w32time.dll and call these from
you application
- ask Microsoft to document the w32time.dll interface
To call the functions in the dll directly, use the LoadLibrary() and
GetProcAddress() functions. Example to resync the local computer (error
handling omitted):
HMODULE h = LoadLibrary("w32time.dll");
W32TimeSyncNow pW32TimeSyncNow = (W32TimeSyncNow)GetProcAddress( h,
"W32TimeSyncNow");
int rv = (pW32TimeSyncNow)(NULL,0x01,0x03);
In case you have to support Windows2000 also, beware: Windows Time on W2K
differs completely from the implementation on XP.
I hope this helps,
Paul.