[python-win32] Strange error with win32security.AdjustTokenPrivileges

Gremlin gremlin at armarize.com
Thu Apr 14 21:52:41 CEST 2011



I want to adapt the following technique into python:

So I started with the following code:


import win32security

import win32process


process = win32process.GetCurrentProcess()

token = win32security.OpenProcessToken(process,

privilege_luid = win32security.LookupPrivilegeValue(None,

privilege = [(privilege_luid, win32security.SE_PRIVILEGE_ENABLED)]

win32security.AdjustTokenPrivileges(token, 0, privilege)


But it fails with the error number 5 (Access denied) once
"AdjustTokenPrivileges" has been executed. That would be obvious if I had
not started python as admin. (Properties -> Start as admin) Also the process
token is another one (at least the integer of token.handle is another one)
if started as non-elevated. I have no idea why this is happening. I do have
the appropriate permissions and the code should be correct. Can anyone help
me? (Btw: My OS is Windows7 Pro 64bit and I'm not a standard user.)





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110414/da0c8f65/attachment.html>

More information about the python-win32 mailing list