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 读取摄像头数据并保存的实例

如下所示: import cv2 cap = cv2.VideoCapture(0) k = 0 while k != 27: # esc ret, img = cap.re...

python机器学习库xgboost的使用

python机器学习库xgboost的使用

1.数据读取 利用原生xgboost库读取libsvm数据 import xgboost as xgb data = xgb.DMatrix(libsvm文件) 使用sk...

python判断端口是否打开的实现代码

复制代码 代码如下:#!/usr/bin/env python# name IsOpen.pyimport osimport socketdef IsOpen(ip,port):&nbs...

Python实现FM算法解析

Python实现FM算法解析

1. 什么是FM? FM即Factor Machine,因子分解机。 2. 为什么需要FM? 1、特征组合是许多机器学习建模过程中遇到的问题,如果对特征直接建模,很有可能会忽略掉特征与特...

Python删除n行后的其他行方法

如下所示: #!/usr/bin/python #-*- coding: utf-8 -*- fin=open('add_1.txt') a=fin.readlines() #...