[python-win32] DuplicateTokenEx
le dahut
le.dahut at laposte.net
Wed Apr 21 11:06:52 CEST 2010
20/04/2010 17:05, Tim Golden wrote :
>
> On 20/04/2010 15:39, le dahut wrote:
>>
>> 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 ?
>
> Just glanced at the code. For some reason the Python function expects
> parameters in this order:
>
> ExistingToken PpyHANDLE)
> ImpersonationLevel (win32security.Security*)
> DesiredAccess (win32security.TOKEN_*)
> TokenType (TokenPrimary or TokenImpersonation)
> TokenAttributes (PySECURITY_ATTRIBUTES)
>
> Note that they can be supplied as keyword args with those names.
Wonderfull, it works now.
Actually I already tested with this order but I was still getting some
errors.
After writing it with ctypes, I've understood that "ImpersonationLevel"
wasn't good.
Now that this option has the right value, everything runs fine !
Thanks.
More information about the python-win32
mailing list