Get a DLL's Version Number


What is the version number of a DLL? This is the "File Version" you get if you open up a DLL's properties and go to the Version tab. The code here only gets the version shown at the top of that tab (on Win2K, anyway). You can use the slightly more messy language-dependent code in the demos which come with pywin32 to find the strings in the box beneath it.

from win32api import GetFileVersionInfo, LOWORD, HIWORD

def get_version_number (filename):
  info = GetFileVersionInfo (filename, "\\")
  ms = info['FileVersionMS']
  ls = info['FileVersionLS']
  return HIWORD (ms), LOWORD (ms), HIWORD (ls), LOWORD (ls)

if __name__ == '__main__':
  import os
  filename = os.environ["COMSPEC"]
  print ".".join ([str (i) for i in get_version_number (filename)])