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.
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...