Example #1
0
def QueryInfoKey(space, w_hkey):
    """tuple = QueryInfoKey(key) - Returns information about a key.

key is an already open key, or any one of the predefined HKEY_* constants.

The result is a tuple of 3 items:
An integer that identifies the number of sub keys this key has.
An integer that identifies the number of values this key has.
A long integer that identifies when the key was last modified (if available)
 as 100's of nanoseconds since Jan 1, 1600."""
    hkey = hkey_w(w_hkey, space)
    with lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as nSubKeys:
        with lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as nValues:
            with lltype.scoped_alloc(rwin32.PFILETIME.TO, 1) as ft:
                null_dword = lltype.nullptr(rwin32.LPDWORD.TO)
                ret = rwinreg.RegQueryInfoKey(hkey, None, null_dword,
                                              null_dword, nSubKeys, null_dword,
                                              null_dword, nValues, null_dword,
                                              null_dword, null_dword, ft)
                if ret != 0:
                    raiseWindowsError(space, ret, 'RegQueryInfoKey')
                l = ((lltype.r_longlong(ft[0].c_dwHighDateTime) << 32) +
                     lltype.r_longlong(ft[0].c_dwLowDateTime))
                return space.newtuple([
                    space.wrap(nSubKeys[0]),
                    space.wrap(nValues[0]),
                    space.wrap(l)
                ])
Example #2
0
def EnumValue(space, w_hkey, index):
    """tuple = EnumValue(key, index) - Enumerates values of an open registry key.
key is an already open key, or any one of the predefined HKEY_* constants.
index is an integer that identifies the index of the value to retrieve.

The function retrieves the name of one subkey each time it is called.
It is typically called repeatedly, until an EnvironmentError exception
is raised, indicating no more values.

The result is a tuple of 3 items:
value_name is a string that identifies the value.
value_data is an object that holds the value data, and whose type depends
 on the underlying registry type.
data_type is an integer that identifies the type of the value data."""
    hkey = hkey_w(w_hkey, space)
    null_dword = lltype.nullptr(rwin32.LPDWORD.TO)

    with lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as retValueSize:
        with lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as retDataSize:
            ret = rwinreg.RegQueryInfoKey(hkey, None, null_dword, null_dword,
                                          null_dword, null_dword, null_dword,
                                          null_dword, retValueSize,
                                          retDataSize, null_dword,
                                          lltype.nullptr(rwin32.PFILETIME.TO))
            if ret != 0:
                raiseWindowsError(space, ret, 'RegQueryInfoKey')
            # include null terminators
            retValueSize[0] += 1
            retDataSize[0] += 1
            bufDataSize = intmask(retDataSize[0])
            bufValueSize = intmask(retValueSize[0])

            with lltype.scoped_alloc(rffi.CCHARP.TO,
                                     intmask(retValueSize[0])) as valuebuf:
                while True:
                    with lltype.scoped_alloc(rffi.CCHARP.TO,
                                             bufDataSize) as databuf:
                        with lltype.scoped_alloc(rwin32.LPDWORD.TO,
                                                 1) as retType:
                            ret = rwinreg.RegEnumValue(hkey, index, valuebuf,
                                                       retValueSize,
                                                       null_dword, retType,
                                                       databuf, retDataSize)
                            if ret == rwinreg.ERROR_MORE_DATA:
                                # Resize and retry
                                bufDataSize *= 2
                                retDataSize[0] = rffi.cast(
                                    rwin32.DWORD, bufDataSize)
                                retValueSize[0] = rffi.cast(
                                    rwin32.DWORD, bufValueSize)
                                continue

                            if ret != 0:
                                raiseWindowsError(space, ret, 'RegEnumValue')

                            length = intmask(retDataSize[0])
                            return space.newtuple([
                                space.wrap(rffi.charp2str(valuebuf)),
                                convert_from_regdata(space, databuf, length,
                                                     retType[0]),
                                space.wrap(retType[0]),
                            ])