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

相关文章

解决pyshp UnicodeDecodeError的问题

用最新版本(2.1.0)的pyshp解析shp文件的records时: records = sf.records() 如果records里面含有中文字段,那么就会报错: Uni...

Pytorch中index_select() 函数的实现理解

函数形式: index_select( dim, index ) 参数: dim:表示从第几维挑选数据,类型为int值; index:表示从第一个参数维度中的哪个...

python中yaml配置文件模块的使用详解

简述 和GNU一样,YAML是一个递归着说“不”的名字。不同的是,GNU对UNIX说不,YAML说不的对象是XML。 YAML不是XML。 为什么不是XML呢?因为: YAML...

更新pip3与pyttsx3文字语音转换的实现方法

我使用的python版本是3.5.2 今天想做个语音读取的小脚本,在网上查了一下发现python里有个pyttsx可以识别文字, 打算通过pip3 install pyttsx安装包,结...

使用TensorFlow实现SVM

使用TensorFlow实现SVM

较基础的SVM,后续会加上多分类以及高斯核,供大家参考。 Talk is cheap, show me the code import tensorflow as tf from s...