Extract Assembly Version from DLL using Python

孤街浪徒 提交于 2019-12-07 15:37:32

问题


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?


回答1:


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/




回答2:


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



来源:https://stackoverflow.com/questions/6470032/extract-assembly-version-from-dll-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!