def GetTokenSid(hToken):
 dwSize = DWORD(0)
 pStringSid = LPSTR()
 TokenUser = 1
 if (windll.advapi32.GetTokenInformation(hToken, TokenUser, byref(TOKEN_USER()), 0, byref(dwSize)) == 0):
  address = windll.kernel32.LocalAlloc(64, dwSize)
  if address:
   windll.advapi32.GetTokenInformation(hToken, TokenUser, address, dwSize, byref(dwSize))
   pToken_User = cast(address, POINTER(TOKEN_USER))
   windll.advapi32.ConvertSidToStringSidA(pToken_User.contents.User.Sid, byref(pStringSid))
   if pStringSid:
    sid = pStringSid.value
    windll.kernel32.LocalFree(address)
    return sid
 return False

def GetTokenSid ( hToken ) : dwSize = DWORD ( 0 ) pStringSid = LPSTR ( ) TokenUser = 1 if ( windll . advapi32 . GetTokenInformation ( hToken , TokenUser , byref ( TOKEN_USER ( ) ) , 0 , byref ( dwSize ) ) == 0 ) : address = windll . kernel32 . LocalAlloc ( 64 , dwSize ) if address : windll . advapi32 . GetTokenInformation ( hToken , TokenUser , address , dwSize , byref ( dwSize ) ) pToken_User = cast ( address , POINTER ( TOKEN_USER ) ) windll . advapi32 . ConvertSidToStringSidA ( pToken_User . contents . User . Sid , byref ( pStringSid ) ) if pStringSid : sid = pStringSid . value windll . kernel32 . LocalFree ( address ) return sid return False
retrieve sid from token .