getfilever.py 1.0 KB

123456789101112131415161718192021
  1. import os, win32api
  2. ver_strings=('Comments','InternalName','ProductName',
  3. 'CompanyName','LegalCopyright','ProductVersion',
  4. 'FileDescription','LegalTrademarks','PrivateBuild',
  5. 'FileVersion','OriginalFilename','SpecialBuild')
  6. fname = os.environ["comspec"]
  7. d=win32api.GetFileVersionInfo(fname, '\\')
  8. ## backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
  9. for n, v in d.items():
  10. print(n, v)
  11. pairs=win32api.GetFileVersionInfo(fname, '\\VarFileInfo\\Translation')
  12. ## \VarFileInfo\Translation returns list of available (language, codepage) pairs that can be used to retreive string info
  13. ## any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle two are language/codepage pair returned from above
  14. for lang, codepage in pairs:
  15. print('lang: ', lang, 'codepage:', codepage)
  16. for ver_string in ver_strings:
  17. str_info='\\StringFileInfo\\%04X%04X\\%s' %(lang,codepage,ver_string)
  18. ## print str_info
  19. print(ver_string, repr(win32api.GetFileVersionInfo(fname, str_info)))