Windows上使用Python增加或删除权限的方法
下面小编就为大家分享一篇Windows上使用Python增加或删除权限的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
在使用Python在 Windows 平台上开发的时候, 有时候我们需要动态增加或删除用户的某些权限, 此时我们可以通过 AdjustTokenPrivileges API 来实现。
比如,我们要给用户分配 SE_TCB_NAME 权限
[code]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)[/code]
比如,我们要给用户去除 SE_TCB_NAME 权限
[code]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) [/code]
以上这篇Windows上使用Python增加或删除权限的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持
经验分享互联网动态
更多阅读推荐