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删除特定文件的方法

本文实例讲述了python删除特定文件的方法。分享给大家供大家参考。具体如下: #!/usr/bin/python # -*- coding: utf-8 -*- import os...

在python里协程使用同步锁Lock的实例

尽管asyncio库是使用单线程来实现协程的,但是它还是并发的,乱序执行的。可以说是单线程的调度系统,并且由于执行时有延时或者I/O中断等因素,每个协程如果同步时,还是得使用一些同步对象...

Python中将dataframe转换为字典的实例

有时候,在Python中需要将dataframe类型转换为字典类型,下面的方法帮助我们解决这一问题。 任务代码。 # encoding: utf-8 import pandas a...

python redis连接 有序集合去重的代码

python redis连接 有序集合去重的代码如下所述: # -*- coding: utf-8 -*- import redis from constant import re...

Python中那些 Pythonic的写法详解

前言 Martin(Bob大叔)曾在《代码整洁之道》一书打趣地说:当你的代码在做 Code Review 时,审查者要是愤怒地吼道: “What the fuck is this shi...