我試過這個代碼:
import win32security
import win32api
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32security.TOKEN_QUERY_SOURCE | win32security.TOKEN_QUERY)
for i in range(0x30):
try:
n = win32security.LookupPrivilegeName(None, i)
privs = win32security.GetTokenInformation(token, i)
except Exception as e:
pass
else:
print(privs)
print(i, n)
while True:
pass
我試圖獲取每個權限的資訊(我主要想要標志),但我無法理解 GetTokenInformation() 的回傳值,它回傳不同的型別,我無法從中提取任何資訊,我在MSDN上搜索,但我仍然不明白。
uj5u.com熱心網友回復:
在 MSDN 中閱讀更多內容后,我發現 GetTokenInformation 函式接收一個名為 TOKEN_INFORMATION_CLASS 的引數,該引數指定函式將回傳的內容,因此為了查找權限及其標志,我使用了以下代碼:
import win32security
import win32api
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32security.TOKEN_QUERY_SOURCE | win32security.TOKEN_QUERY)
privs = win32security.GetTokenInformation(token, win32security.TokenPrivileges)
for i in range(len(privs)):
# name of privilege
name = win32security.LookupPrivilegeName(None, privs[i][0])
flag = privs[i][1]
# check the flag value
if flag == 0:
flag = 'Disabled'
elif flag == 3:
flag = 'Enabled'
print(name, flag)
while True:
pass
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/345294.html
下一篇:需要幫助來設定RichEdit
