Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SNTP time is not updating while working on wince6.0.

29 views
Skip to first unread message

priyankaahire

unread,
Oct 3, 2008, 10:35:14 AM10/3/08
to
I would like to update the time of my device running windows ce 6.0
using an sntp Server.

I read help in MSDN SNTP registry settings. I searched google groups
and set the entries:

00 "Server"=string:ntp0.fau.de \
01 "threshold"=dword:86400000 \
02 "recoveryrefresh"=dword:86400000 \
03 "refresh"=dword:604800000 \
04 "trustlocalclock"=dword:0 \
05 "clientonly"=dword:1 \
06 "Context"=dword:0 \
07 "Dll"=string:timesvc.dll \
08 "Order"=dword:153 \
09 "Keep"=dword:1 \
10 "Prefix"=string:NTP \
11 "Index"=dword:0 \

This did not work, I think there is no NTP update started.

I tried the same at my pc Windows XP set the save server.
Kommandline:
net stop w32time
net start w32time

the time was updated.

My device is in the same network.

After that, I tried to find out the status of the sntp service of my
device.

The following code
- stops the service
- gets the status
- starts the service
- gets the status
until here everything works fine

Now I try IOCTL_SERVICE_CONTROL and "Set" or "Sync" and I get error
code 87 wrong parameter. But this code is out of
MSDN: http://msdn2.microsoft.com/en-us/library/ms899593.aspx

Does anybody have an idea what I do wrong? I don't get an updated
time.

#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <Service.h>

int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFile=CreateFile(TEXT("NTP0:"),GENERIC_READ|GENERIC_WRITE,
0,NULL,OPEN_EXISTING,0,NULL);

if(INVALID_HANDLE_VALUE!=hFile)
{
_tprintf(TEXT("Successful device opening.\n"));

DWORD dwState = 100;

DWORD err = 0;
// stop the SNTP service
if(!DeviceIoControl(hFile, IOCTL_SERVICE_STOP, NULL, 0, NULL, 0,
NULL, NULL))
{
err = GetLastError();
if(err == 1062)
_tprintf(TEXT("The service has not been started.\n"));

}

if(!DeviceIoControl(hFile, IOCTL_SERVICE_STATUS, NULL, 0, &dwState,
sizeof(DWORD), NULL,NULL))//IOCTL_SERVICE_CONTROL ,szControlString,
dwLenIn
{
err = GetLastError();

_tprintf(TEXT("Unsucessful to get State.\n"));
_tprintf(TEXT("Error code: %d\n"), err);
}
else
{
switch(dwState)
{
case 0:
_tprintf(TEXT("SERVICE_STATE_OFF\n"));
break;
case 1:
_tprintf(TEXT("SERVICE_STATE_ON\n"));
break;
case 2:
_tprintf(TEXT("SERVICE_STATE_STARTING_UP\n"));
break;
case 3:
_tprintf(TEXT("SERVICE_STATE_SHUTTING_DOWN\n"));
break;
case 4:
_tprintf(TEXT("SERVICE_STATE_UNLOADING\n"));
break;
case 5:
_tprintf(TEXT("SERVICE_STATE_UNINITIALIZED\n"));
break;

default:
_tprintf(TEXT("SERVICE_STATE_UNKNOWN\n"));
break;
}
}

// start the SNTP service
if(!DeviceIoControl(hFile, IOCTL_SERVICE_START, NULL, 0, NULL, 0,
NULL, NULL))
{
err = GetLastError();
}

if(!DeviceIoControl(hFile, IOCTL_SERVICE_STATUS, NULL, 0, &dwState,
sizeof(DWORD), NULL,NULL))
{
err = GetLastError();

_tprintf(TEXT("Unsucessful to get State.\n"));
_tprintf(TEXT("Error code: %d\n"), err);
}
else
{
switch(dwState)
{
case 0:
_tprintf(TEXT("SERVICE_STATE_OFF\n"));
break;
case 1:
_tprintf(TEXT("SERVICE_STATE_ON\n"));
break;
case 2:
_tprintf(TEXT("SERVICE_STATE_STARTING_UP\n"));
break;
case 3:
_tprintf(TEXT("SERVICE_STATE_SHUTTING_DOWN\n"));
break;
case 4:
_tprintf(TEXT("SERVICE_STATE_UNLOADING\n"));
break;
case 5:
_tprintf(TEXT("SERVICE_STATE_UNINITIALIZED\n"));
break;

default:
_tprintf(TEXT("SERVICE_STATE_UNKNOWN\n"));
break;
}
}

WCHAR szControlString[]=L"sync";
DWORD dwLenIn=sizeof(szControlString);
DWORD dwBytesReturned = -1;

// Example MSDN
//WCHAR szControlString[]=L"sync";
//DWORD dwLenIn=sizeof(szControlString);
//DWORD dwBytesReturned;
//DeviceIoControl(hFile, IOCTL_SERVICE_CONTROL, szControlString,
dwLenIn, NULL, 0, &dwBytesReturned, NULL);
// Example MSDN END

// !!!!!!!!!! err = 87 wrong Parameter !!!!!!!!!!!!!!!!
ERROR_INVALID_PARAMETER - The parameter is incorrect. - 87
if(!DeviceIoControl(hFile, IOCTL_SERVICE_CONTROL,
szControlString,dwLenIn, NULL ,0, &dwBytesReturned, NULL))
{
err = GetLastError();
_tprintf(TEXT("Error code: %d\n"), err);
}
else
{
_tprintf(TEXT("Successful time update!!!\n"));
}

// REFRESH
if (DeviceIoControl(hFile, IOCTL_SERVICE_REFRESH, NULL, 0, NULL, 0,
NULL, NULL))
_tprintf(TEXT("Service Refresh Successful.\n"));

CloseHandle(hFile);
}
else
{
_tprintf(TEXT("Unsuccessful device opening.\n"));
}

return 0;
}


well i have checked services list command but it is not running running.
what kind of issue is this can anybody knows this issue?
Thank you very much.
Priyanka.

Paul G. Tobey [eMVP]

unread,
Oct 6, 2008, 12:42:39 PM10/6/08
to
So, you do 'services list' at the MS-DOS prompt and what do you get back for
the time service? 95% of the problems with the time service are you setting
invalid registry parameters, so make sure that your refresh interval is long
enough, that your max adjustment (threshold), is large enough, that the
server is pingable, of course. Since you're doing a sync, that should
update the local clock in most cases. I'd create an AutoUpdate entry, even
if you don't expect to have the service update periodically. There might be
a failure if that entry isn't present.

If you think that your parameters are correct, you could try sending "Sync",
not "sync". Looking at my code, that's what it sends. You wouldn't think
that it would be case-sensitive, but who knows. If that doesn't help, you
should have the source code for the service. Make sure that the registry
parameters that you think are set are actually visible from Remote Registry
Editor and hand-trace the code for the Sync case to see what you might have
missed.

Paul T.

"priyankaahire" <u46662@uwe> wrote in message news:8b1c6d86874d0@uwe...

0 new messages