#include <Service.h>
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFile = CreateFile(TEXT("NTP0:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
// Stop SNTP service
DeviceIoControl(hFile, IOCTL_SERVICE_STOP, NULL, 0, NULL, 0, NULL, NULL);
// Get service status
DeviceIoControl(hFile, IOCTL_SERVICE_STATUS, NULL, 0, &dwState, sizeof(DWORD), NULL,NULL);
// Start the SNTP service
DeviceIoControl(hFile, IOCTL_SERVICE_START, NULL, 0, NULL, 0, NULL, NULL);
// set sync event
DeviceIoControl(hFile, IOCTL_SERVICE_CONTROL, L"Sync", sizeof(L"Sync"), NULL, 0, NULL, NULL);
// Refresh
DeviceIoControl(hFile, IOCTL_SERVICE_REFRESH, NULL, 0, NULL, 0, NULL, NULL);
CloseHandle(hFile);
return 0;
}
好像不會一執行馬上就同步,執行後要等一小小段時間。
沒有留言:
張貼留言