Home > Backend Development > Python Tutorial > How to use Python to add or remove permissions on Windows

How to use Python to add or remove permissions on Windows

不言
Release: 2018-04-24 13:37:09
Original
2222 people have browsed it

The following is an article about how to use Python to add or delete permissions on Windows. It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together

When using Python to develop on the Windows platform, sometimes we need to dynamically add or delete certain permissions of the user. At this time, we can achieve this through the AdjustTokenPrivileges API.

For example, we want to assign the SE_TCB_NAME permission to the user

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)
Copy after login

For example, we want to remove SE_TCB_NAME permissions from users

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)
Copy after login

Related recommendations:

Introduction to how to add screen clearing function in Python

The above is the detailed content of How to use Python to add or remove permissions on Windows. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template