python禁用键鼠与提权代码实例

yipeiwu_com6年前Python基础

要求

利用python实现禁用键盘鼠标

思路

经过查阅资料目前最好的办法是采用ctypes中的dll文件进行编写

from ctypes import *
improt time
print(winll.shell32.IsUserAnAdmin()) #判断是否有管理员权限
user32 = windll.LoadLibrary("C:\\Windows\\System32\\user32.dll")
user32.BlockInput(True) #该功能需要管理员权限 True 禁用
time.sleep(5)
user32.BlockInput(Flase) #该功能需要管理员权限 
time.sleep(5) 

提权

def requireAdministrator(f):
  def inner(*args, **kwargs):
    if windll.shell32.IsUserAnAdmin():
      f()
    else:
      # Re-run the program with admin rights
      windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 0)
      f()
  return inner

官方文档

工欲善其事,必先利其器!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python 对字典按照value进行排序的方法

字典按照value进行排序共有三种方法 d = {'a': 1, 'b': 4, 'c': 2, 'f' : 12} # 第一种方法,key使用lambda匿名函数取value进...

Python数据结构与算法之二叉树结构定义与遍历方法详解

本文实例讲述了Python数据结构与算法之二叉树结构定义与遍历方法。分享给大家供大家参考,具体如下: 先序遍历,中序遍历,后序遍历 ,区别在于三条核心语句的位置 层序遍历  采...

python在命令行下使用google翻译(带语音)

说明1. 使用google翻译服务获得翻译和语音;2. 使用mplayer播放获得的声音文件,因此,如果要播放语音,请确保PATH中能够找到mplayer程序,如果没有mplayer,请...

Python的subprocess模块总结

subprocess意在替代其他几个老的模块或者函数,比如:os.system os.spawn* os.popen* popen2.* commands.* subprocess最简单...

Python二分查找详解

先来看个实例 #!/usr/bin/env python import sys def search2(a,m): low = 0 high = len(a)...