Windows上使用Python增加或删除权限的方法

yipeiwu_com7年前Python基础

在使用Python在 Windows 平台上开发的时候, 有时候我们需要动态增加或删除用户的某些权限, 此时我们可以通过 AdjustTokenPrivileges API 来实现。

比如,我们要给用户分配 SE_TCB_NAME 权限

flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), flags)
id = win32security.LookupPrivilegeValue(None, win32security.SE_TCB_NAME)
privilege = [(id, win32security.SE_PRIVILEGE_ENABLED)]
print win32security.AdjustTokenPrivileges(token, False, privilege)

比如,我们要给用户去除 SE_TCB_NAME 权限

flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), flags)
id = win32security.LookupPrivilegeValue(None, win32security.SE_TCB_NAME)
privilege = [(id, 0)]
print win32security.AdjustTokenPrivileges(token, False, privilege)

以上这篇Windows上使用Python增加或删除权限的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

numpy数组拼接简单示例

NumPy数组是一个多维数组对象,称为ndarray。其由两部分组成: ·实际的数据 ·描述这些数据的元数据 大部分操作仅针对于元数据,而不改变底层实际的数据。 关于NumPy数组有几点...

python3+PyQt5+Qt Designer实现堆叠窗口部件

python3+PyQt5+Qt Designer实现堆叠窗口部件

本文是对《Python Qt GUI快速编程》的第9章的堆叠窗口例子Vehicle Rental用Python3+PyQt5+Qt Designer进行改写。 第一部分无借用Qt De...

linux下安装easy_install的方法

如果想使用easy_install工具,可能需要先安装setuptools,不过更酷的方法是使用ez_setup.py脚本:复制代码 代码如下:wget -q http://peak.t...

Python入门之三角函数sin()函数实例详解

描述 sin()返回的x弧度的正弦值。 语法 以下是sin()方法的语法: importmath math.sin(x) 注意:sin()是不能直接访问的,需要导入math模块,...

python识别文字(基于tesseract)代码实例

python识别文字(基于tesseract)代码实例

这篇文章主要介绍了python识别文字(基于tesseract)代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 Ubuntu版...