Expand Minimize

SetThreadToken function

The SetThreadToken function assigns an impersonation token to a thread. The function can also cause a thread to stop using an impersonation token.

Syntax


BOOL WINAPI SetThreadToken(
  _In_opt_  PHANDLE Thread,
  _In_opt_  HANDLE Token
);

Parameters

Thread [in, optional]

A pointer to a handle to the thread to which the function assigns the impersonation token.

If Thread is NULL, the function assigns the impersonation token to the calling thread.

Token [in, optional]

A handle to the impersonation token to assign to the thread. This handle must have been opened with TOKEN_IMPERSONATE access rights. For more information, see Access Rights for Access-Token Objects.

If Token is NULL, the function causes the thread to stop using an impersonation token.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

When using the SetThreadToken function to impersonate, you must have the impersonate privileges and make sure that the SetThreadToken function succeeds before calling the RevertToSelf function.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Winbase.h (include Windows.h)

Library

Advapi32.lib

DLL

Advapi32.dll

See also

Access Control Overview
Basic Access Control Functions
OpenThreadToken

 

 

Community Additions

ADD
Show:
© 2014 Microsoft