Search the Community
Showing results for tags 'different'.
-
The following code contains 2 functions to achieve the same results, although function2 works fine whereas function1 returns different results ;#include <Array.au3> #include <security.au3> #include <WinAPI.au3> #include <ProcessConstants.au3> Global Const $TOKEN_MAXIMUM_ALLOWED = 0x02000000 Func _GetTokenPSid($hToken) Local $aCall = DllStructGetData(_Security__GetTokenInformation($hToken, $TOKENUSER), 1) $tempPtr = DllStructCreate("PTR") $ptrSize = DllStructGetSize($tempPtr) $rawSid = BinaryMid($aCall, $ptrSize * 2 + 1, BinaryLen($aCall)) $mem = DllStructCreate("byte Attributes[" & BinaryLen($rawSid) & "]") DllStructSetData($mem, "Attributes", $rawSid) $pSid = DllStructGetPtr($mem) Return $pSid EndFunc ;==>_GetTokenPSid Func _GetTokenUser1($hToken) $pSid = _GetTokenPSid($hToken) Local $aCall = DllCall("advapi32.dll", "bool", "LookupAccountSidW", "ptr", "", "ptr", $pSid, "wstr", "", "dword*", 65536, "wstr", "", "dword*", 65536, "int*", 0) If IsArray($aCall) Then Return $aCall[5] & "\" & $aCall[3] Else Return "" EndIf EndFunc ;==>_GetTokenUser Func _GetTokenUser2($hToken) Local $aCall = DllStructGetData(_Security__GetTokenInformation($hToken, $TOKENUSER), 1) $tempPtr = DllStructCreate("PTR") $ptrSize = DllStructGetSize($tempPtr) $rawSid = BinaryMid($aCall, $ptrSize * 2 + 1, BinaryLen($aCall)) $mem = DllStructCreate("byte Attributes[" & BinaryLen($rawSid) & "]") DllStructSetData($mem, "Attributes", $rawSid) $pSid = DllStructGetPtr($mem) Local $bCall = DllCall("advapi32.dll", "bool", "LookupAccountSidW", "ptr", "", "ptr", $pSID, "wstr", "", "dword*", 65536, "wstr", "", "dword*", 65536, "int*", 0) If IsArray($bCall) Then Return $bCall[5] & "\" & $bCall[3] Else Return "" EndIf EndFunc Func _ProcessTokenInfo($pid) $hToken = _Security__OpenProcessToken(_WinAPI_OpenProcess($TOKEN_MAXIMUM_ALLOWED, 0, $pid), $TOKEN_QUERY) If Not $hToken Then $hToken = _Security__OpenProcessToken(_WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, 0, $pid), $TOKEN_QUERY) EndIf ConsoleWrite("GetTokenUser1 : " & _GetTokenUser1($hToken) & @CRLF) ConsoleWrite("GetTokenUser2 : " & _GetTokenUser2($hToken) & @CRLF) ConsoleWrite(@CRLF) _WinAPI_CloseHandle($hToken) Return EndFunc ;==>_ProcessTokenInfo For $i = 1 To 10 _ProcessTokenInfo(856) Next Below are the results Am I doing something wrong here ?