public static SafeHandle GetTokenInformation(SafeCloseHandle token, TOKEN_INFORMATION_CLASS infoClass) { uint length; if (!SafeNativeMethods.GetTokenInformation(token, infoClass, SafeHGlobalHandle.InvalidHandle, 0, out length)) { int error = Marshal.GetLastWin32Error(); if (error != (int)Win32Error.ERROR_INSUFFICIENT_BUFFER) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error, SR.GetString(SR.GetTokenInfoFailed, error))); } } SafeHandle buffer = SafeHGlobalHandle.AllocHGlobal(length); try { if (!SafeNativeMethods.GetTokenInformation(token, infoClass, buffer, length, out length)) { int error = Marshal.GetLastWin32Error(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error, SR.GetString(SR.GetTokenInfoFailed, error))); } } catch { buffer.Dispose(); throw; } return(buffer); }
public static SafeHandle GetTokenInformation(SafeCloseHandle token, TOKEN_INFORMATION_CLASS infoClass) { uint num; if (!SafeNativeMethods.GetTokenInformation(token, infoClass, SafeHGlobalHandle.InvalidHandle, 0, out num)) { int error = Marshal.GetLastWin32Error(); if (error != 0x7a) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error, System.ServiceModel.SR.GetString("GetTokenInfoFailed", new object[] { error }))); } } SafeHandle tokenInformation = SafeHGlobalHandle.AllocHGlobal(num); try { if (!SafeNativeMethods.GetTokenInformation(token, infoClass, tokenInformation, num, out num)) { int num3 = Marshal.GetLastWin32Error(); throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(num3, System.ServiceModel.SR.GetString("GetTokenInfoFailed", new object[] { num3 }))); } } catch { tokenInformation.Dispose(); throw; } return(tokenInformation); }