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

通过ctypes库,您可以避免使用pywin32来查询文件版本信息。这段代码展示了如何使用GetFileVersionInfoSizeA、Create_string_buffer、VerQueryValueA等函数从Windows系统文件中提取文件版本详情。
摘要由CSDN通过智能技术生成

如果您不希望使用pywin32来实现这一点,那么可以使用ctypes来实现这一点。在

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

有一个old mailing list post在做你要求的事情。不幸的是,我现在没有现成的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')

好的-回到一个windows盒子旁边。现在已经试过了。”为我工作”。在

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值