4

I'm trying to extract some version information from a DLL using python. I read this question: Python windows File Version attribute

It was helpful, but I also need to get the 'Assembly version' from the DLL. It's there when I right click and look on the versions tab, but not sure how I extract this with python.

On this page: http://timgolden.me.uk/python/win32_how_do_i/get_dll_version.html

Tim Golden says:

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.

Can someone point me to the example that might be useful? I looked in the win32api directories but there's nothing obvious. Would I find a solution there?

Community
  • 1
  • 1
Mark Irvine
  • 1,349
  • 14
  • 24

2 Answers2

4

If you would rather not introduce a dependency on Python.Net, you can also use the win32 api directly:

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)

Source: http://timgolden.me.uk/python/win32_how_do_i/get_dll_version.html

Tom Makin
  • 3,203
  • 23
  • 23
3

I'm not sure you can get at this information by using native code. The usual way of obtaining the assembly info is by running .Net code (e.g. C#). So I'm guessing in order to be able to do the same from python you'll need to run some .Net python interpreter. See for example http://pythonnet.github.io/

denfromufa
  • 5,610
  • 13
  • 81
  • 138
Assaf Lavie
  • 73,079
  • 34
  • 148
  • 203