Ejemplo n.º 1
0
def get_open_with_list(ext):
    """get open with list of an ext

    find all the exe programs and direct program

    @params:
        ext --  file extention

    """
    import re

    sub_key = '\\'.join([
        ext, 'OpenWithList'
    ])

    try:
        key = OpenKey(HKEY_CLASSES_ROOT, sub_key)
    except WindowsError:
        return None

    key_no = QueryInfoKey(key)[0]

    exes = []
    for index in xrange(key_no):
        exe = EnumKey(key, index)
        if exe.lower().endswith('.exe'):
            command = get_exe_command(exe)
            if not command:
                continue
            match = re.search(u'.+\\\\(.+)\\\\(\w+)\.exe', command,  flags=re.IGNORECASE)
            if match:
                name = match.group(2)
                progid = '.'.join([name, 'edo'])
                exes.append((name, progid, command))
        else:
            sub_key = '\\'.join([
                exe, 'shell', 'edit', 'command'
            ])
            edit_command = get_command(key, sub_key)
            sub_key = '\\'.join([
                exe, 'shell', 'open', 'command'
            ])
            open_command = get_command(key, sub_key)

            if not (open_command or edit_command):
                continue

            command = edit_command or open_command
            match = re.search(u'.+\\\\(.+)\\\\(\w+)\.exe', command,  flags=re.IGNORECASE)
            if match:
                name = match.group(2)
                progid = '.'.join([name, 'edo'])
                exes.append((name, progid, command))

    return exes
Ejemplo n.º 2
0
def get_open_with_list(ext):
    """get open with list of an ext

    find all the exe programs and direct program

    @params:
        ext --  file extention

    """
    import re

    sub_key = '\\'.join([ext, 'OpenWithList'])

    try:
        key = OpenKey(HKEY_CLASSES_ROOT, sub_key)
    except WindowsError:
        return None

    key_no = QueryInfoKey(key)[0]

    exes = []
    for index in xrange(key_no):
        exe = EnumKey(key, index)
        if exe.lower().endswith('.exe'):
            command = get_exe_command(exe)
            if not command:
                continue
            match = re.search(u'.+\\\\(.+)\\\\(\w+)\.exe',
                              command,
                              flags=re.IGNORECASE)
            if match:
                name = match.group(2)
                progid = '.'.join([name, 'edo'])
                exes.append((name, progid, command))
        else:
            sub_key = '\\'.join([exe, 'shell', 'edit', 'command'])
            edit_command = get_command(key, sub_key)
            sub_key = '\\'.join([exe, 'shell', 'open', 'command'])
            open_command = get_command(key, sub_key)

            if not (open_command or edit_command):
                continue

            command = edit_command or open_command
            match = re.search(u'.+\\\\(.+)\\\\(\w+)\.exe',
                              command,
                              flags=re.IGNORECASE)
            if match:
                name = match.group(2)
                progid = '.'.join([name, 'edo'])
                exes.append((name, progid, command))

    return exes