[python-win32] exe version information and icon extraction?

James Carroll mrmaple at gmail.com
Wed Jan 25 15:52:34 CET 2006


> You can use win32api.GetFileVersionInfo to retrieve all the version
> properties.  See \win32\demos\getfilever.py for usage.

Thanks everyone, that was easy.  My resulting code looks like this:

try:
    # if the target is an exe, get the file information
    pairs = wapi.GetFileVersionInfo(target, '\\VarFileInfo\\Translation')
    (lang, codepage) = pairs[0]
    path = u'\\StringFileInfo\\%04X%04X\\%%s' %(lang,codepage)
    prodName = wapi.GetFileVersionInfo(target, path%"ProductName")
    prodVersion = wapi.GetFileVersionInfo(target, path%"ProductVersion")

    # get the exe resources, and see if they match our app
    #exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
    #icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
    link = {}
    link["linkName"] = linkName
    link["target"] = target
    link["startIn"] = startIn
    link["description"] = description
    link["version"] = prodVersion

    link["icon"] = ico = wx.Icon(target, wx.BITMAP_TYPE_ICO)
    bmp = wx.EmptyBitmap(32,32)
    bmp.CopyFromIcon(ico)
    img = wx.ImageFromBitmap(bmp)
    #

    self.list.append(link)
    #
except Exception, e:
    print "%s has no resources: %s" % (target, e)
#

-Jim


More information about the Python-win32 mailing list