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设计】。

相关文章

写了个监控nginx进程的Python脚本

复制代码 代码如下: #!/usr/bin/env python import os, sys, time while True: time.sleep(3) try: ret = os...

python中将字典转换成其json字符串

#这是Python中的一个字典 dic = { 'str': 'this is a string', 'list': [1, 2, 'a', 'b'], 'sub_dic': {...

使用pandas读取csv文件的指定列方法

根据教程实现了读取csv文件前面的几行数据,一下就想到了是不是可以实现前面几列的数据。经过多番尝试总算试出来了一种方法。 之所以想实现读取前面的几列是因为我手头的一个csv文件恰好有后面...

python pandas修改列属性的方法详解

使用astype如下: df[[column]] = df[[column]].astype(type) type即int、float等类型。 示例: import panda...

下载官网python并安装的步骤详解

下载官网python并安装的步骤详解

怎么下载官网python并安装? Python火了起来,很多人开始学习起来了,那么Python安装包,去哪里下载呢。那当然是去官网咯。 Python官网或直接 访问 https://ww...