一.功能描述:

如果当前笔记本自带键盘已禁用,那么运行后就会启用(需要重启)
如果当前笔记本自带键盘已启用,那么运行后就会禁用(需要重启)

二.注意:

1.config文件不要随意修改(路径和exe文件同级)
2.运行完成后需要重启电脑

三.源码:

#!/usr/bin/env python
# coding:utf8
import subprocess
import ctypes, sys
def is_admin():
    "是否是管理员"
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False
def findStartType(filePath,str):
    "查找文件中是否有str"
    with open(filePath, 'r') as f:
        context = f.readlines()

    target_line = 0
    for l in context:
        if l.find(str) != -1:
            return True
        target_line += 1
    return False
def runCmd(cmd):
    "运行cmd命令"
    if is_admin():
        recode = subprocess.Popen(cmd,shell=True)
    else:
        if sys.version_info[0] == 3:
            ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
        else:#in python2.x
            ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)
def keyboard():
    "禁用或启用自带键盘"
    scqc_i8042prt()
    cmd_disabled = "sc config i8042prt start= disabled"  # 禁用
    cmd_demand = "sc config i8042prt start= demand"  # 启用
    if findStartType("config.txt","DISABLED"):
        runCmd(cmd_demand)
    else:
        runCmd(cmd_disabled)
def scqc_i8042prt():
    "查询i8042prt的状态"
    cmd = "sc qc i8042prt -t>config.txt"
    runCmd(cmd)
def main():
    "主函数"
    keyboard()
if __name__ == '__main__':
    main()

四.exe文件

exe文件链接
链接失效的话可以到我上传的资源中去找

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐