# File lib/facter/util/windows/process.rb, line 13
  def open_process_token(handle, desired_access, &block)
    token_handle = nil
    begin
      FFI::MemoryPointer.new(:handle, 1) do |token_handle_ptr|
        result = OpenProcessToken(handle, desired_access, token_handle_ptr)
        if result == Facter::Util::Windows::FFI::WIN32_FALSE
          raise Facter::Util::Windows::Error.new(
              "OpenProcessToken(#{handle}, #{desired_access.to_s(8)}, #{token_handle_ptr})")
        end

        yield token_handle = Facter::Util::Windows::FFI.read_handle(token_handle_ptr)
      end

      token_handle
    ensure
      Facter::Util::Windows::FFI::WIN32.CloseHandle(token_handle) if token_handle
    end

    # token_handle has had CloseHandle called against it, so nothing to return

    nil
  end