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

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

相关文章

python 自定义异常和异常捕捉的方法

异常捕捉: try: XXXXX1 raise Exception(“xxxxx2”) except (Exception1,Exception2,……): xxxx3...

python2.7+selenium2实现淘宝滑块自动认证功能

python2.7+selenium2实现淘宝滑块自动认证功能

本文为大家分享了python2.7+selenium2实现淘宝滑块自动认证的具体代码,供大家参考,具体内容如下 1.编译环境 操作系统:win7;语言:python2.7+selen...

python Elasticsearch索引建立和数据的上传详解

python Elasticsearch索引建立和数据的上传详解

今天我想讲一讲关于Elasticsearch的索引建立,当然提前是你已经安装部署好Elasticsearch。 ok,先来介绍一下Elaticsearch,它是一款基于lucene的实时...

tensorflow入门:TFRecordDataset变长数据的batch读取详解

在上一篇文章tensorflow入门:tfrecord 和tf.data.TFRecordDataset的使用里,讲到了使用如何使用tf.data.TFRecordDatase来对tfr...

python常用排序算法的实现代码

这篇文章主要介绍了python常用排序算法的实现代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 排序是计算机语言需要实现的基本算法...