[python-win32] Strange error with win32security.AdjustTokenPrivileges

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


Hello.

 

I want to adapt the following technique into python:
http://blogs.msdn.com/b/aaron_margosis/archive/2009/06/06/faq-how-do-i-start
-a-program-as-the-desktop-user-from-an-elevated-app.aspx

So I started with the following code:

 

import win32security

import win32process

 

process = win32process.GetCurrentProcess()

token = win32security.OpenProcessToken(process,
win32security.TOKEN_ADJUST_PRIVILEGES)

privilege_luid = win32security.LookupPrivilegeValue(None,
win32security.SE_INCREASE_QUOTA_NAME)

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.)

 

Regards,

Johannes

 

-------------- 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