Beispiel #1
0
    def getFileVersion(self,filename):
        from ctypes.wintypes import (
            windll, sizeof, WinError, byref, POINTER, cast, c_char, Structure, c_uint,
            pointer, BOOL, DWORD, LPVOID, LPCVOID, LPCWSTR,
        )

        class VS_FIXEDFILEINFO(Structure):
            _fields_ = [
                ("dwSignature", DWORD), # will be 0xFEEF04BD
                ("dwStrucVersion", DWORD),
                ("dwFileVersionMS", DWORD),
                ("dwFileVersionLS", DWORD),
                ("dwProductVersionMS", DWORD),
                ("dwProductVersionLS", DWORD),
                ("dwFileFlagsMask", DWORD),
                ("dwFileFlags", DWORD),
                ("dwFileOS", DWORD),
                ("dwFileType", DWORD),
                ("dwFileSubtype", DWORD),
                ("dwFileDateMS", DWORD),
                ("dwFileDateLS", DWORD)
        ]

        PUINT = POINTER(c_uint)
        LPDWORD = POINTER(DWORD)

        GetFileVersionInfoSizeW = windll.version.GetFileVersionInfoSizeW
        GetFileVersionInfoSizeW.restype = DWORD
        GetFileVersionInfoSizeW.argtypes = [LPCWSTR, LPDWORD]
        GetFileVersionInfoSize = GetFileVersionInfoSizeW # alias

        GetFileVersionInfoW = windll.version.GetFileVersionInfoW
        GetFileVersionInfoW.restype = BOOL
        GetFileVersionInfoW.argtypes = [LPCWSTR, DWORD, DWORD, LPVOID]
        GetFileVersionInfo = GetFileVersionInfoW # alias

        VerQueryValueW = windll.version.VerQueryValueW
        VerQueryValueW.restype = BOOL
        VerQueryValueW.argtypes = [LPCVOID, LPCWSTR, POINTER(LPVOID), PUINT]
        VerQueryValue = VerQueryValueW # alias

        filename = unicode(filename)
    
        dwLen  = GetFileVersionInfoSize(filename, None)
        if not dwLen :
            raise WinError()
        lpData = (c_char * dwLen)()
        if not GetFileVersionInfo(filename, 0, sizeof(lpData), lpData):
            raise WinError()
        uLen = c_uint()
        lpffi = POINTER(VS_FIXEDFILEINFO)()
        lplpBuffer = cast(pointer(lpffi), POINTER(LPVOID))
        if not VerQueryValue(lpData, u"\\", lplpBuffer, byref(uLen)):
            raise WinError()
        ffi = lpffi.contents
        return [int(ffi.dwFileVersionMS >> 16),
            int(ffi.dwFileVersionMS & 0xFFFF),
            int(ffi.dwFileVersionLS >> 16),
            int(ffi.dwFileVersionLS & 0xFFFF)]
def GetFileVersion(filename):
    dwLen = GetFileVersionInfoSize(filename, None)
    if not dwLen:
        raise WinError()
    lpData = (c_char * dwLen)()
    if not GetFileVersionInfo(filename, 0, sizeof(lpData), lpData):
        raise WinError()
    uLen = c_uint()
    lpffi = POINTER(VS_FIXEDFILEINFO)()
    lplpBuffer = cast(pointer(lpffi), POINTER(LPVOID))
    if not VerQueryValue(lpData, u"\\", lplpBuffer, byref(uLen)):
        raise WinError()
    ffi = lpffi.contents
    return (
        ffi.dwFileVersionMS >> 16,
        ffi.dwFileVersionMS & 0xFFFF,
        ffi.dwFileVersionLS >> 16,
        ffi.dwFileVersionLS & 0xFFFF,
    )
Beispiel #3
0
def GetFileVersion(filename):
    dwLen  = GetFileVersionInfoSize(filename, None)
    if not dwLen:
        raise WinError()
    lpData = (c_char * dwLen)()
    if not GetFileVersionInfo(filename, 0, sizeof(lpData), lpData):
        raise WinError()
    uLen = c_uint()
    lpffi = POINTER(VS_FIXEDFILEINFO)()
    lplpBuffer = cast(pointer(lpffi), POINTER(LPVOID))
    if not VerQueryValue(lpData, u"\\", lplpBuffer, byref(uLen)):
        raise WinError()
    ffi = lpffi.contents
    return (
        ffi.dwFileVersionMS >> 16,
        ffi.dwFileVersionMS & 0xFFFF,
        ffi.dwFileVersionLS >> 16,
        ffi.dwFileVersionLS & 0xFFFF,
    )
Beispiel #4
0
 def from_PSAFEARRAY(self, psafearray):
     res = cast(psafearray, POINTER(ImprovedSAFEARRAY))[0]
     return res
Beispiel #5
0
 def from_PSAFEARRAY(self, psafearray):
     res = cast(psafearray, POINTER(ImprovedSAFEARRAY))[0]
     return res