tags:

views:

99

answers:

1

I would like to get file version info for executable files on Windows with Ruby.

Is there a way to do that?

+1  A: 

This was posted in an answer to another question:

require "Win32API"
FILENAME = "c:/ruby/bin/ruby.exe" #your filename here
s=""
vsize=Win32API.new('version.dll', 'GetFileVersionInfoSize', 
                   ['P', 'P'], 'L').call(FILENAME, s)
p vsize
if (vsize > 0)
  result = ' '*vsize
  Win32API.new('version.dll', 'GetFileVersionInfo', 
               ['P', 'L', 'L', 'P'], 'L').call(FILENAME, 0, vsize, result)
  rstring = result.unpack('v*').map{|s| s.chr if s<256}*''
  r = /FileVersion..(.*?)\000/.match(rstring)
  puts "FileVersion = #{r ? r[1] : '??' }"
else
  puts "No Version Info"
end
bluehavana