首页 栏目2 电脑时间无法修改 电脑无法修改系统时间

电脑时间无法修改 电脑无法修改系统时间

import ctypes, sys
import ntplib
import time
import os
import datetime


def ntptime():
     连接阿里云NTP服务器
    response = ntplib.NTPClient().request(&39;ntp.aliyun.com&39;)
    ts = response.tx_time
    _date = time.strftime(&39;%Y-%m-%d&39;, time.localtime(ts))
    _time = time.strftime(&39;%X&39;, time.localtime(ts))
    curtime=&39;date {} && time {}&39;.format(_date, _time)
    os.system(curtime)
    t1 = time.strftime(&39;%Y-%m-%d %X&39;, time.localtime(ts))
    t2 = datetime.datetime.now().strftime(&39;%Y-%m-%d %X&39;)
    if t1 == t2:
        print(&39;\n\nNTP网络对时成功,阿里NTP服务器返回的时间为:  {}   {}&39;.format(_date, _time))
    else:
        print(&39;NTP对时失败&39;)
 
 显示一下结果
    variable = input(&34;\n\n按回车键退出!&34;)

def is_admin():
    try:
         获取当前用户的是否为管理员,修改系统时间要以管理员身份运行程序
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False
 
if is_admin():
    ntptime()
else:
     重新运行这个程序使用管理员权限
    ctypes.windll.shell32.ShellExecuteW(None, &34;runas&34;, sys.executable, __file__, None, 1)
版权声明:本网站内容来源于网络和互联网作者投稿,本站不享有任何版权,如有侵权请联系删除 QQ邮箱:11111111@.qq.com

作者: tiger

为您推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 *标注