How to invoke NTP sync from python on windows?

0

I've tried the following code

import os
os.system('w32tm /resync')

But the result was

The following error occurred: The service has not been started. (0x80070426)

I'm pretty sure the time service was started on a prior run by itself so this was odd - maybe it doesn't automatically run in-between restarts but then I'm not sure how it started before. In any case, running Net start w32time solved the not running issue. But then from the python script I get:

Sending resync command to local computer
The following error occurred: Access is denied. (0x80070005)

I'd like for my script to be able to run ntp sync whenever I detect time issue from my application so that the application can control its destiny but I also would like to keep privileges where they are without having to elevate privileges to get the command to work. I looked into ntplib and I don't think it offers resyncing functions but ability to query time from time servers. A workaround is to run an external task that continues to resync a defined period.

Is there a way to run a NTP sync command from my script instead? Machine is windows 10.

python
windows-10
ntp
asked on Stack Overflow Mar 13, 2021 by LeanMan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0