Exemplo n.º 1
0
def getFileProperties(fname):
    propNames = ('Comments', 'InternalName', 'ProductName', 'CompanyName',
                 'LegalCopyright', 'ProductVersion', 'FileDescription',
                 'LegalTrademarks', 'PrivateBuild', 'FileVersion',
                 'OriginalFilename', 'SpecialBuild')
    props = {
        'FixedFileInfo': None,
        'StringFileInfo': None,
        'FileVersion': None
    }
    try:
        fixedInfo = win32api.GetFileVersionInfo(fname, '\\')
        #        print(fixedInfo)
        props['FixedFileInfo'] = fixedInfo
        props['FileVersion'] = "%d.%d.%d.%d" % (
            fixedInfo['FileVersionMS'] / 65536, fixedInfo['FileVersionMS'] %
            65536, fixedInfo['FileVersionLS'] / 65536,
            fixedInfo['FileVersionLS'] % 65536)
        lang, codepage = win32api.GetFileVersionInfo(
            fname, '\\VarFileInfo\\Translation')[0]
        strInfo = {}
        for propName in propNames:
            strInfoPath = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage,
                                                               propName)
            strInfo[propName] = win32api.GetFileVersionInfo(fname, strInfoPath)
        props['StringFileInfo'] = strInfo
    except Exception as e:
        print(e)
        pass
    return props
Exemplo n.º 2
0
def get_file_win_properties(fname):
    propNames = ('Comments', 'InternalName', 'ProductName', 'CompanyName',
                 'LegalCopyright', 'ProductVersion', 'FileDescription',
                 'LegalTrademarks', 'PrivateBuild', 'FileVersion',
                 'OriginalFilename', 'SpecialBuild')

    props = {'FileVersion': "0.0.0"}

    try:
        # backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
        fixedInfo = win32api.GetFileVersionInfo(fname, '\\')
        props['FixedFileInfo'] = fixedInfo
        props['FileVersion'] = "%d.%d.%d.%d" % (
            fixedInfo['FileVersionMS'] / 65536, fixedInfo['FileVersionMS'] %
            65536, fixedInfo['FileVersionLS'] / 65536,
            fixedInfo['FileVersionLS'] % 65536)

        # \VarFileInfo\Translation returns list of available (language, codepage)
        # pairs that can be used to retreive string info. We are using only the first pair.
        lang, codepage = win32api.GetFileVersionInfo(
            fname, '\\VarFileInfo\\Translation')[0]

        strInfo = {}
        for propName in propNames:
            strInfoPath = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage,
                                                               propName)
            strInfo[propName] = win32api.GetFileVersionInfo(fname, strInfoPath)

        props['StringFileInfo'] = strInfo
    except:
        pass

    return props
Exemplo n.º 3
0
def get_fileversioninfo(filename):
	"""
	Read all properties of the given file return them as a dictionary.
	"""
	import win32api
	propNames = ('Comments', 'InternalName', 'ProductName',
				 'CompanyName', 'LegalCopyright', 'ProductVersion',
				 'FileDescription', 'LegalTrademarks', 'PrivateBuild',
				 'FileVersion', 'OriginalFilename', 'SpecialBuild')

	props = {'FixedFileInfo': None, 'StringFileInfo': None, 'FileVersion': None}

	# backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
	fixedInfo = win32api.GetFileVersionInfo(filename, '\\')
	props['FixedFileInfo'] = fixedInfo
	props['FileVersion'] = "%d.%d.%d.%d" % (fixedInfo['FileVersionMS'] / 65536,
											fixedInfo['FileVersionMS'] % 65536, fixedInfo['FileVersionLS'] / 65536,
											fixedInfo['FileVersionLS'] % 65536)

	# \VarFileInfo\Translation returns list of available (language, codepage)
	# pairs that can be used to retreive string info. We are using only the first pair.
	lang, codepage = win32api.GetFileVersionInfo(filename, '\\VarFileInfo\\Translation')[0]

	# any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
	# two are language/codepage pair returned from above

	strInfo = {}
	for propName in propNames:
		strInfoPath = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage, propName)
		strInfo[propName] = win32api.GetFileVersionInfo(filename, strInfoPath)

	props['StringFileInfo'] = strInfo
	return props
Exemplo n.º 4
0
def CopyAddinFile(assembly, path, vs_version):
    """Copy the .AddIn file to the given path while making the necessary
  replacements.

  The version number is obtained from the NativeClientAddIn.dll assembly which
  is built during the build process.
  """
    infopath = '\\VarFileInfo\\Translation'
    pairs = win32api.GetFileVersionInfo(assembly, infopath)
    lang, codepage = pairs[0]
    infopath = u'\\StringFileInfo\\%04X%04X\\ProductVersion' % (lang, codepage)
    prodVersion = win32api.GetFileVersionInfo(assembly, infopath)
    version = '[%s]' % prodVersion
    print('NaCl VS Add-in %s version: %s' % (vs_version, version))

    metadata_filename = os.path.basename(ADDIN_METADATA)
    modified_file = join(path, metadata_filename)

    # Copy the metadata file to new location and modify the version info.
    with open(ADDIN_METADATA, 'r') as source_file:
        with open(modified_file, 'w') as dest_file:
            data = source_file.read()
            replacements = {'VS_VERSION': vs_version, 'ADDIN_VERSION': version}
            data = string.Template(data).substitute(replacements)
            dest_file.write(data)
Exemplo n.º 5
0
def get_file_info(filename):
    """ Get exe/dll file information """
    info = {"FileInfo": None, "StringFileInfo": {}, "FileVersion": None}

    finfo = win32api.GetFileVersionInfo(filename, "\\")
    info["FileInfo"] = finfo
    info["FileVersion"] = "%i.%i.%i.%i" % (
        finfo["FileVersionMS"] / 65536, finfo["FileVersionMS"] % 65536,
        finfo["FileVersionLS"] / 65536, finfo["FileVersionLS"] % 65536)
    for lcid, codepage in win32api.GetFileVersionInfo(
            filename, "\\VarFileInfo\\Translation"):
        info["StringFileInfo"][lcid, codepage] = {}
        for name in [
                "Comments", "CompanyName", "FileDescription", "FileVersion",
                "InternalName", "LegalCopyright", "LegalTrademarks",
                "OriginalFilename", "PrivateBuild", "ProductName",
                "ProductVersion", "SpecialBuild"
        ]:
            value = win32api.GetFileVersionInfo(
                filename,
                "\\StringFileInfo\\%04X%04X\\%s" % (lcid, codepage, name))
            if value is not None:
                info["StringFileInfo"][lcid, codepage][name] = value

    return info
Exemplo n.º 6
0
    def update(self):
        zpf = self.extract()
        current_info = win32api.GetFileVersionInfo('launcher.exe', "\\")
        current_ms = current_info['FileVersionMS']
        current_ls = current_info['FileVersionLS']
        current_version = "%d.%d.%d.%d" % (
            win32api.HIWORD(current_ms), win32api.LOWORD(current_ms),
            win32api.HIWORD(current_ls), win32api.LOWORD(current_ls))
        current_ver = parse_version(current_version)

        new_info = win32api.GetFileVersionInfo(
            os.path.join(zpf, 'launcher.exe'), "\\")
        new_ms = new_info['FileVersionMS']
        new_ls = new_info['FileVersionLS']
        new_version = "%d.%d.%d.%d" % (
            win32api.HIWORD(new_ms), win32api.LOWORD(new_ms),
            win32api.HIWORD(new_ls), win32api.LOWORD(new_ls))
        new_ver = parse_version(new_version)

        if new_ver > current_ver:
            self.install(zpf)
            print(f"Update Finished! {current_ver} -> {new_ver}")
        else:
            print(
                f"Update Failed! Package {new_ver} is either older or equivalent to the current installation {current_ver}"
            )
Exemplo n.º 7
0
def _query_string_field_version(file_name, version_prefix):
    """
    Retrieves the version with the specified prefix from the specified file via
    its string fields.

    :param file_name: The file from which the version should be read.
    :param version_prefix: The prefix to use. Can be either FileVersion or
    ProductVersion.
    :return: A 4-tuple of integers containing the version of the file.
    """
    # We need to ask for language and copepage first, before we can
    # query the actual version.
    l_query = u'\\VarFileInfo\\Translation'
    try:
        lang, codepage = win32api.GetFileVersionInfo(file_name, l_query)[0]
    except win32api.error:
        # File does not have a string field section
        return 0, 0, 0, 0
    ver_query = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage,
                                                     version_prefix)
    full_ver = win32api.GetFileVersionInfo(file_name, ver_query)
    # xSE uses commas in its version fields, so use this 'heuristic'
    split_on = u',' if u',' in full_ver else u'.'
    try:
        return tuple([int(part) for part in full_ver.split(split_on)])
    except ValueError:
        return 0, 0, 0, 0
Exemplo n.º 8
0
def getfileprop(filepath: str) -> dict:
    """Read all properties of a local file and return them as a dictionary"""
    import win32api

    filepath = str(filepath)
    propNames = (
        "Comments",
        "InternalName",
        "ProductName",
        "CompanyName",
        "LegalCopyright",
        "ProductVersion",
        "FileDescription",
        "LegalTrademarks",
        "PrivateBuild",
        "FileVersion",
        "OriginalFilename",
        "SpecialBuild",
    )

    props = {
        "FixedFileInfo": None,
        "StringFileInfo": None,
        "FileVersion": None
    }

    try:
        # backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
        fixedInfo = win32api.GetFileVersionInfo(filepath, "\\")
        props["FixedFileInfo"] = fixedInfo
        props["FileVersion"] = "%d.%d.%d.%d" % (
            fixedInfo["FileVersionMS"] / 65536,
            fixedInfo["FileVersionMS"] % 65536,
            fixedInfo["FileVersionLS"] / 65536,
            fixedInfo["FileVersionLS"] % 65536,
        )

        # \VarFileInfo\Translation returns list of available (language, codepage)
        # pairs that can be used to retreive string info. We are using only the first pair.
        lang, codepage = win32api.GetFileVersionInfo(
            filepath, "\\VarFileInfo\\Translation")[0]

        # any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
        # two are language/codepage pair returned from above

        strInfo = {}
        for propName in propNames:
            strInfoPath = "\\StringFileInfo\\%04X%04X\\%s" % (lang, codepage,
                                                              propName)
            strInfo[propName] = win32api.GetFileVersionInfo(
                filepath, strInfoPath)

        props["StringFileInfo"] = strInfo
    except Exception as e:
        logging.error(f'Unable to Read file properties due to "{e}"')
        pass

    return props
Exemplo n.º 9
0
def checkVersion(COM_path):
    if not os.path.isfile(COM_path):
        COM_path = "不存在"
        LastestVersion, LastestVersionName = "不存在", "不存在"
    else:
        LastestVersionName = win32api.GetFileVersionInfo(
            COM_path, '\\StringFileInfo\\040904b0\\ProductName')
        LastestVersion = win32api.GetFileVersionInfo(
            COM_path, '\\StringFileInfo\\040904b0\\FileVersion')
    return COM_path, LastestVersionName, LastestVersion
Exemplo n.º 10
0
 def get_version_string(filename, key):
     try:
         translations = win32api.GetFileVersionInfo(filename, "\\VarFileInfo\\Translation")
     except Exception:
         return u""
     else:
         # use the first available language
         language, codepage = translations[0]
         return win32api.GetFileVersionInfo(
             filename, "\\StringFileInfo\\%04x%04x\\%s" % (language, codepage, key))
Exemplo n.º 11
0
def getFileProperties(path):
    """
    读取给定文件的所有属性, 返回一个字典.
    """

    props = {'FixedFileInfo': None, 'StringFileInfo': None}

    # A = None
    try:
        fixedFileInfo = {'FixedFileInfo': None, 'StringFileInfo': {}}
        fixedInfo = win32api.GetFileVersionInfo(path, '\\')
        # print(fixedInfo.get('StrucVersion'))
        # print(fixedInfo.get('Signature'))

        struc = 65536
        fixedFileInfo['filevers'] = "%d.%d.%d.%d" % (
            fixedInfo.get('FileVersionMS') / struc, fixedInfo.get('FileVersionMS') % struc,
            fixedInfo.get('FileVersionLS') / struc, fixedInfo.get('FileVersionLS') % struc)
        fixedFileInfo['prodvers'] = "%d.%d.%d.%d" % (
            fixedInfo.get('ProductVersionMS') / struc, fixedInfo.get('ProductVersionMS') % struc,
            fixedInfo.get('ProductVersionLS') / struc, fixedInfo.get('ProductVersionLS') % struc)
        fixedFileInfo['mask'] = fixedInfo.get('FileFlagsMask')
        fixedFileInfo['flags'] = fixedInfo.get('FileFlags')
        fixedFileInfo['OS'] = fixedInfo.get('FileOS')
        fixedFileInfo['fileType'] = fixedInfo.get('FileType')
        fixedFileInfo['subtype'] = fixedInfo.get('FileSubtype')
        fixedFileInfo['date'] = fixedInfo.get('FileDate')
        props['FixedFileInfo'] = fixedFileInfo
        print(fixedFileInfo)

        # \VarFileInfo\Translation returns list of available (language, codepage)
        # pairs that can be used to retreive string info. We are using only the first pair.
        lang, codepage = win32api.GetFileVersionInfo(path, '\\VarFileInfo\\Translation')[0]

        # any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
        # two are language/codepage pair returned from above

        propNames = ('Comments', 'InternalName', 'ProductName',
                     'CompanyName', 'LegalCopyright', 'ProductVersion',
                     'FileDescription', 'LegalTrademarks', 'PrivateBuild',
                     'FileVersion', 'OriginalFilename', 'SpecialBuild',)
        strInfo = {}
        for propName in propNames:
            strInfoPath = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage, propName)
            ## print str_info
            strInfo[propName] = win32api.GetFileVersionInfo(path, strInfoPath)

        props['StringFileInfo'] = strInfo
        print(strInfo)
    except Exception as e:
        print(e.__dict__)
        props['code'] = e.winerror
        props['msg'] = e.strerror

    return props
Exemplo n.º 12
0
def version():
    if isWindowsExe():
        # stump: if we've been py2exe'd, read our version string from the exe.
        import win32api
        us = os.path.abspath(
            unicode(sys.executable, sys.getfilesystemencoding()))
        version = win32api.GetFileVersionInfo(
            us, r'\StringFileInfo\%04x%04x\ProductVersion' %
            win32api.GetFileVersionInfo(us, r'\VarFileInfo\Translation')[0])
    else:
        version = "%s %s" % (versionNum(), revision())
    return version
Exemplo n.º 13
0
def getFileDescription(
        windows_exe):  # find description of exe for different languages
    try:
        language, codepage = win32api.GetFileVersionInfo(
            windows_exe, '\\VarFileInfo\\Translation')[0]
        stringFileInfo = u'\\StringFileInfo\\%04X%04X\\%s' % (
            language, codepage, "FileDescription")
        description = win32api.GetFileVersionInfo(windows_exe, stringFileInfo)
    except Exeption as err:
        print('error', err)

    return description
Exemplo n.º 14
0
 def get_file_info(self, file_path, contribution_list):
     if not isinstance(contribution_list, list):
         raise ValueError('"get_file_info" function need a list, not %s' % type(contribution_list))
     try:
         lang, code_page = win32api.GetFileVersionInfo(file_path, '\\VarFileInfo\\Translation')[0]
         for contribution_name in contribution_list:
             str_info_path = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, code_page, contribution_name)
             if contribution_name == 'signature':
                 self.get_digital_signature_info(file_path)
             else:
                 self.info[contribution_name] = win32api.GetFileVersionInfo(file_path, str_info_path)
     except:
         pass
     return self.info
Exemplo n.º 15
0
 def isSystemDLL(pathname):
     if build_exe._isSystemDLL(pathname):
         return True
     try:
         language = win32api.GetFileVersionInfo(
             pathname, '\\VarFileInfo\\Translation')
         company = win32api.GetFileVersionInfo(
             pathname,
             '\\StringFileInfo\\%.4x%.4x\\CompanyName' % language[0])
         if company.lower() == 'microsoft corporation':
             return True
     except Exception:
         pass
     return False
Exemplo n.º 16
0
def getProcessName(executable):
    if executable in knownProcesses:
        return knownProcesses[executable]
    try:
        language, codepage = win32api.GetFileVersionInfo(
            executable, "\\VarFileInfo\\Translation")[0]
        stringFileInfo = u"\\StringFileInfo\\%04X%04X\\%s" % (
            language, codepage, "FileDescription")
        description = win32api.GetFileVersionInfo(executable, stringFileInfo)
        if description == None:
            raise Exception("ProcessName not found.")
    except:
        description = executable
    return description
Exemplo n.º 17
0
    def get_file_properties(cls, file) -> dict:
        """
        Read all properties of the given file and return them as a dictionary.

        EXAMPLE::

            prop = FileHelper.get_file_properties(r"C:\\Windows\\System32\\cmd.exe")
            for key, value in prop['StringFileInfo'].items():
                print(f'{key:<15} {value if value else "":<30}')
        """

        prop_names = ('Comments', 'InternalName', 'ProductName', 'CompanyName',
                      'LegalCopyright', 'ProductVersion', 'FileDescription',
                      'LegalTrademarks', 'PrivateBuild', 'FileVersion',
                      'OriginalFilename', 'SpecialBuild')

        return_dict = {
            'FixedFileInfo': None,
            'StringFileInfo': None,
            'FileVersion': None
        }
        try:
            # backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
            fixed_info = win32api.GetFileVersionInfo(file, '\\')
            return_dict['FixedFileInfo'] = fixed_info
            return_dict['FileVersion'] = "%d.%d.%d.%d" % (
                fixed_info['FileVersionMS'] / 65536,
                fixed_info['FileVersionMS'] % 65536,
                fixed_info['FileVersionLS'] / 65536,
                fixed_info['FileVersionLS'] % 65536)

            # \VarFileInfo\Translation returns list of available (language, code-page)
            # pairs that can be used to retrieve string info. We are using only the first pair.
            lang, codepage = win32api.GetFileVersionInfo(
                file, '\\VarFileInfo\\Translation')[0]

            # any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
            # two are language/codepage pair returned from above
            dict_info = {}
            for cur_prop_name in prop_names:
                prop_name = u'\\StringFileInfo\\%04X%04X\\%s' % (
                    lang, codepage, cur_prop_name)
                dict_info[cur_prop_name] = win32api.GetFileVersionInfo(
                    file, prop_name)
            return_dict['StringFileInfo'] = dict_info
        except:
            pass
        return return_dict
Exemplo n.º 18
0
def version():
    if hasattr(sys, 'frozen'):
        # stump: if we've been py2exe'd, read our version string from the exe.
        if sys.frozen == 'windows_exe':
            import win32api
            us = os.path.abspath(
                unicode(sys.executable, sys.getfilesystemencoding()))
            version = win32api.GetFileVersionInfo(
                us, r'\StringFileInfo\%04x%04x\ProductVersion' %
                win32api.GetFileVersionInfo(us,
                                            r'\VarFileInfo\Translation')[0])
        else:
            version = VERSION
    else:
        version = "%s %s" % (VERSION, revision())
    return version
Exemplo n.º 19
0
    def __init__(self, location, password):
        self.__location = location
        self.__password = password

        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
                             r'SOFTWARE\BigFix\Enterprise Server',
                             access=winreg.KEY_WOW64_32KEY
                             | winreg.KEY_QUERY_VALUE)
        server_location = winreg.QueryValueEx(key, 'EnterpriseServerFolder')[0]
        self.port = int(winreg.QueryValueEx(key, 'Port')[0])
        key.Close()
        besadmin_location = os.path.join(server_location, 'BESAdmin.exe')

        self._run_command = '"{0}" ' \
                            '/sitePvkLocation:"{1}" ' \
                            '/evalExpressPassword:{2}'.format(besadmin_location,
                                                              location,
                                                              password)

        info = win32api.GetFileVersionInfo(besadmin_location, '\\')
        ms = info['FileVersionMS']
        ls = info['FileVersionLS']

        self.version = '{0}.{1}.{2}.{3}'.format(win32api.HIWORD(ms),
                                                win32api.LOWORD(ms),
                                                win32api.HIWORD(ls),
                                                win32api.LOWORD(ls))
        self.major_version = '.'.join(self.version.split('.')[0:2])
Exemplo n.º 20
0
def getFileVersion(file_name):
    info = win32api.GetFileVersionInfo(file_name, os.sep)
    ms = info['FileVersionMS']
    ls = info['FileVersionLS']
    version = '%d.%d.%d.%04d' % (win32api.HIWORD(ms), win32api.LOWORD(ms),
                                 win32api.HIWORD(ls), win32api.LOWORD(ls))
    return version
Exemplo n.º 21
0
    def get_installed_browser_version(self):
        """
      method for reading the version of chrome currently installed.
      """
        if self.os_name == 'win':

            Registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
            with winreg.OpenKey(
                    Registry,
                    "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe"
            ) as key:
                chrome_path = winreg.QueryValueEx(key, 'Path')[0]
                if 'chrome.exe' not in chrome_path:
                    chrome_path += '\\chrome.exe'

            exe_info = win32api.GetFileVersionInfo(chrome_path, '\\')

            installed_chrome_version = "%d.%d.%d.%d" % (
                exe_info['FileVersionMS'] / 65536, exe_info['FileVersionMS'] %
                65536, exe_info['FileVersionLS'] / 65536,
                exe_info['FileVersionLS'] % 65536)

            return installed_chrome_version

        else:
            raise NotImplementedError(
                "Checking installed Chrome Version is currently only supported on Windows."
            )
Exemplo n.º 22
0
Arquivo: update.py Projeto: riku22/TCV
def _getFileVersion(filePath):
    info = win32api.GetFileVersionInfo(filePath, os.sep)
    ms = info['FileVersionMS']
    ls = info['FileVersionLS']
    version = '%d.%d.%d' % (win32api.HIWORD(ms), win32api.LOWORD(ms),
                            win32api.HIWORD(ls))
    return version
Exemplo n.º 23
0
def get_file_version(filename):
    """Raises LookupError if file has no version.
  Returns (major, minor, micro)"""
    import platform
    if platform.system() == 'Windows':
        import win32api
        ffi = win32api.GetFileVersionInfo(filename, "\\")

        # I don't know the difference between ProductVersion and FileVersion
        def extract_16s(i32):
            return ((i32 >> 16) & 0xffff), i32 & 0xffff

        file_version = extract_16s(ffi['FileVersionMS']) + extract_16s(
            ffi['FileVersionLS'])
        return file_version[0:3]
    else:
        raise LookupError("Not supported yet on macOS")
        # Untested -- get it from the property list
        import json
        from subprocess import check_output
        plist_file = os.path.join(filename, 'Contents', 'Info.plist')
        plist_json = check_output(
            ['plutil', '-convert', 'json', '-o', '-', '-s', '--', plist_file])
        plist = json.loads(plist_json)
        # XXX: need to parse this out but I don't know the format
        return plist['CFBundleShortVersionString']
Exemplo n.º 24
0
def get_sqlserver_info(c, sys, infolist):
    if sys == "Windows":
        cmd = get_Proceess_cmd(c, "sqlservr")
        tempdict = dict()
        if cmd == "":
            tempdict["sqlserver"] = False
            print "sqlserver server:" + str(tempdict["sqlserver"])
        else:
            tempdict["sqlserver"] = True
            print "sqlserver server:" + str(tempdict["sqlserver"])
            temp = cmd.split("sqlservr")[0]
            if temp.find("\"") >= 0:
                tempdict["basedir"] = temp.split("\"")[1]
            else:
                tempdict["basedir"] = temp
            print "basedir:" + tempdict["basedir"]
            #version
            binpath = tempdict["basedir"] + "sqlservr.exe"
            try:
                verinfo = win32api.GetFileVersionInfo(binpath, "\\")
                tempdict["version"] = "%d.%.2d.%d.%d" % (
                    verinfo["ProductVersionMS"] / 65536,
                    verinfo["ProductVersionMS"] % 65536,
                    verinfo["ProductVersionLS"] / 65536,
                    verinfo["ProductVersionLS"] % 65536)
            except:
                tempdict["version"] = ""
            print "version:" + tempdict["version"]
        infolist.append(tempdict)
Exemplo n.º 25
0
    def get_file_version(filename, parts=None):
        """
        Returns version of win-executable file.
        :param filename:
        :param parts: Number of version parts to return
        """
        logging.debug(filename)
        try:
            info = win32api.GetFileVersionInfo(filename, "\\")
            ms = info['FileVersionMS']
            ls = info['FileVersionLS']
            if parts == 1:
                return "{0}".format(win32api.HIWORD(ms))
            if parts == 2:
                return "{0}.{1}".format(win32api.HIWORD(ms),
                                        win32api.LOWORD(ms))
            if parts == 3:
                return "{0}.{1}.{2}".format(win32api.HIWORD(ms),
                                            win32api.LOWORD(ms),
                                            win32api.HIWORD(ls))

            return "{0}.{1}.{2}.{3}".format(win32api.HIWORD(ms),
                                            win32api.LOWORD(ms),
                                            win32api.HIWORD(ls),
                                            win32api.LOWORD(ls))
        except Exception:
            return None
Exemplo n.º 26
0
 def get_d2_version(self):
     if self.is_d2se:
         d2se_patch = self.pm.read_string(self.base_address +
                                          0x1A049).strip()
         if d2se_patch not in [
                 '1.07', '1.08', '1.09b', '1.09d', '1.10f', '1.11b',
                 '1.12a', '1.13c'
         ]:
             d2se_patch = '1.13c'
         return d2se_patch
     try:
         decoded_filename = self.pm.process_base.filename.decode('utf-8')
     except UnicodeDecodeError:
         # Handle issues with decoding umlauts
         decoded_filename = self.pm.process_base.filename.decode(
             'windows-1252')
     fixed_file_info = win32api.GetFileVersionInfo(decoded_filename, '\\')
     raw_version = '{:d}.{:d}.{:d}.{:d}'.format(
         fixed_file_info['FileVersionMS'] // 65536,
         fixed_file_info['FileVersionMS'] % 65536,
         fixed_file_info['FileVersionLS'] // 65536,
         fixed_file_info['FileVersionLS'] % 65536)
     patch_map = {
         '1.14.3.71': '1.14d',
         '1.14.2.70': '1.14c',
         '1.14.1.68': '1.14b',
         '1.0.13.64': '1.13d',
         '1.0.13.60': '1.13c'
     }
     return patch_map.get(raw_version, raw_version)
Exemplo n.º 27
0
def get_file_version1(folder_path):
    file_path = get_all_files(folder_path)
    i = 0
    dict2 = {}
    for key in file_path:

        pe_names = list(file_path.values())
        try:
            info = win32api.GetFileVersionInfo(key, '\\')
            ms = info['FileVersionMS']
            ls = info['FileVersionLS']
            version = '%d.%d.%d.%d' % (win32api.HIWORD(ms), win32api.LOWORD(
                ms), win32api.HIWORD(ls), win32api.LOWORD(ls))

            dict1 = {pe_names[i]: version}
            dict2.update(dict1)
            i = i + 1
        except:
            print("the file no version:" + key)

    print(dict2)
    return dict2


#test = get_file_version1("C:\\Program Files (x86)\\COMODO\\test")
def _verifyPywin32():
    import os

    if not os.name in ['nt']:
        return (True, 'PyWin32 is not used on non-Windows systems.')
    
    output = []
    pywin32_needed = False

    try:
        import pywintypes
        import win32api
        goodToGo = True
        fixed_file_info = win32api.GetFileVersionInfo(win32api.__file__, '\\')
        pywin32_ver = fixed_file_info['FileVersionLS'] >> 16
        output += ["You have PyWin32 build {0}".format(pywin32_ver)]        
    except ImportError:
        goodToGo = False
        pywin32_needed = True

    if pywin32_needed:
        output +=  ["You need to install PyWin32:"]
        output +=  [" - information http://sourceforge.net/projects/pywin32/"]
        output +=  [" - download and install the latest release for your Python version from http://sourceforge.net/projects/pywin32/files/pywin32/"]
        
    return (goodToGo,'\n'.join(output))
Exemplo n.º 29
0
def get_version_number (path: pathlib.Path):
  """Retrieve the version number of a binary file."""
  
  info = win32api.GetFileVersionInfo(str(path), "\\")
  ms = info['FileVersionMS']
  ls = info['FileVersionLS']
  return win32api.HIWORD (ms), win32api.LOWORD (ms), win32api.HIWORD (ls), win32api.LOWORD (ls)
def _GetProductName(file_path):
  """Returns the product name of the given file.

  Args:
    file_path: The absolute or relative path to the file.

  Returns:
    A string representing the product name of the file, or None if the product
    name was not found.
  """
  language_and_codepage_pairs = win32api.GetFileVersionInfo(
      file_path, '\\VarFileInfo\\Translation')
  if not language_and_codepage_pairs:
    return None
  product_name_entry = ('\\StringFileInfo\\%04x%04x\\ProductName' %
                        language_and_codepage_pairs[0])
  return win32api.GetFileVersionInfo(file_path, product_name_entry)