--Execute with administrator privileges
Sample.py
# coding: Shift_JIS
from ctypes import Structure, windll, pointer
from ctypes.wintypes import WORD
#Create a structure to pass to the time synchronization function.
class SYSTEMTIME(Structure):
    _fields_ = [
      ('wYear',            WORD),
      ('wMonth',           WORD),
      ('wDayOfWeek',       WORD),
      ('wDay',             WORD),
      ('wHour',            WORD),
      ('wMinute',          WORD),
      ('wSecond',          WORD),
      ('wMilliseconds',    WORD),
    ]
#Put data in the structure of the set time
setTimeData = SYSTEMTIME()
setTimeData.wYear = 2018
setTimeData.wMonth = 11
setTimeData.wDayOfWeek = 0  #The day of the week is selfish
setTimeData.wDay = 15
setTimeData.wHour = 17
setTimeData.wMinute = 0
setTimeData.wSecond = 0
setTimeData.wMilliseconds = 0
#Time synchronization part
SetLocalTime = windll.kernel32.SetLocalTime
ret = SetLocalTime(pointer(setTimeData))
#Result judgment
if ret == 0:
    print('Setting failed. Execute with administrator privileges.')
else:
    print('Succeeded. Shut down the system.')
Because C functions can be used with the convenience of Python Speaking of convenience, it is convenient.
Recommended Posts