从Python中查找应用程序的版本?

从Python中查找应用程序的版本?,python,winapi,Python,Winapi,基本上,我试图找出用户当前安装的ArcGIS的版本,我查看了注册表,没有找到任何与版本字符串相关的内容。但是我知道它存储在.exe中 我在谷歌上搜索了一段时间,找不到任何真正值得的东西。我试着使用GetFileVersionInfo,但我似乎得到了一堆随机的东西 有什么想法吗 编辑 唉 事实证明并非所有机器上都安装了pywin32。有人知道是否可以通过ctypes做同样的事情吗 此外,这仅适用于windows。有一个名为“strings”的gnu linux实用程序,它可以打印任何文件(二进制或

基本上,我试图找出用户当前安装的ArcGIS的版本,我查看了注册表,没有找到任何与版本字符串相关的内容。但是我知道它存储在.exe中

我在谷歌上搜索了一段时间,找不到任何真正值得的东西。我试着使用GetFileVersionInfo,但我似乎得到了一堆随机的东西

有什么想法吗

编辑

事实证明并非所有机器上都安装了pywin32。有人知道是否可以通过ctypes做同样的事情吗


此外,这仅适用于windows。

有一个名为“strings”的gnu linux实用程序,它可以打印任何文件(二进制或非二进制)中的可打印字符,请尝试使用它并查找类似于模式的版本号


在windows上,您可以在此处获取字符串

如果您不希望使用pywin32执行此操作,那么您肯定可以使用ctypes执行此操作

诀窍是解码返回的愚蠢的文件版本结构

有一个正在按你的要求做。不幸的是,我现在手头没有一个windows设备来测试这个。但如果它不起作用,至少应该给你一个好的开始

这是代码,以防2006年的档案在某个时候消失:

import array
from ctypes import *

def get_file_info(filename, info):
    """
    Extract information from a file.
    """
    # Get size needed for buffer (0 if no info)
    size = windll.version.GetFileVersionInfoSizeA(filename, None)
    # If no info in file -> empty string
    if not size:
        return ''
    # Create buffer
    res = create_string_buffer(size)
    # Load file informations into buffer res
    windll.version.GetFileVersionInfoA(filename, None, size, res)
    r = c_uint()
    l = c_uint()
    # Look for codepages
    windll.version.VerQueryValueA(res, '\\VarFileInfo\\Translation',
                                  byref(r), byref(l))
    # If no codepage -> empty string
    if not l.value:
        return ''
    # Take the first codepage (what else ?)
    codepages = array.array('H', string_at(r.value, l.value))
    codepage = tuple(codepages[:2].tolist())
    # Extract information
    windll.version.VerQueryValueA(res, ('\\StringFileInfo\\%04x%04x\\'
+ info) % codepage, byref(r), byref(l))
    return string_at(r.value, l.value)

print get_file_info(r'C:\WINDOWS\system32\calc.exe', 'FileVersion')
--

好-回到一个窗口框附近。我现在已经试过这个代码了。“为我工作”

>>> print get_file_info(r'C:\WINDOWS\system32\calc.exe', 'FileVersion')
6.1.7600.16385 (win7_rtm.090713-1255)