I want to use python to get the executable file version, and i know of pefile.py
how to use it to do this?
notes: the executable file may be not complete.
I want to use python to get the executable file version, and i know of pefile.py
how to use it to do this?
notes: the executable file may be not complete.
The version numbers of Windows programs are stored in the resource section of the program file, not in the PE format header. I'm not familiar with pefile.py
, so I don't know whether it directly handles resource sections too. If not, you should be able to find the information you need for that in this MSDN article.
Assuming by "executable file version" you mean a) on Windows, b) the information shown in the Properties, Details tab, under "File version", you can retrieve this using the pywin32 package with a command like the following:
>>> import win32api as w
>>> hex(w.GetFileVersionInfo('c:/windows/regedit.exe', '\\')['FileVersionMS'])
'0x60000'
>>> hex(w.GetFileVersionInfo('c:/windows/regedit.exe', '\\')['FileVersionLS'])
'0x17714650'
Note that 0x60000 has the major/minor numbers (6.0) and 0x17714650 is the next two, which if taken as two separate words (0x1771 and 0x4650, or 6001 and 18000 in decimal) correspond to the values on my machine, where regedit's version is 6.0.6001.18000.