[python-win32] DuplicateTokenEx

le dahut le.dahut at laposte.net
Tue Apr 20 16:39:41 CEST 2010


Hello,

I'm trying to use "win32security.DuplicateTokenEx" but I encounter an error.

My code looks like this :
"""
def getusertoken():
     # process.get_pids(procname) returns a list of the pids of running 
copies of "<procname>"
     # for "winlogon" I suppose there is only one copy
     p = win32api.OpenProcess(1024, 0, process.get_pids('winlogon.exe')[0])
     t = win32security.OpenProcessToken(p, win32security.TOKEN_DUPLICATE)
     return win32security.DuplicateTokenEx(t,
                                           win32con.MAXIMUM_ALLOWED,
 
win32security.SECURITY_ATTRIBUTES(),
 
win32security.SecurityIdentification,
                                           win32security.TokenPrimary
                                           )
"""

The error is :
TypeError: DuplicateTokenEx() argument 3 must be integer<k>, not 
PySECURITY_ATTRIBUTES


MSDN says :
BOOL WINAPI DuplicateTokenEx(
   __in      HANDLE hExistingToken,
   __in      DWORD dwDesiredAccess,
   __in_opt  LPSECURITY_ATTRIBUTES lpTokenAttributes,
   __in      SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
   __in      TOKEN_TYPE TokenType,
   __out     PHANDLE phNewToken
);

Is there is a problem with python implementation of "DuplicateTokenEx" 
or am I doing something wrong ?




More information about the python-win32 mailing list