Exemplo n.º 1
0
def __FindSvcDeps(findName):
    if isinstance(findName, pywintypes.UnicodeType):
        findName = str(findName)
    dict = {}
    k = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE,
                            "SYSTEM\\CurrentControlSet\\Services")
    num = 0
    while True:
        try:
            svc = win32api.RegEnumKey(k, num)
        except win32api.error:
            break
        num = num + 1
        sk = win32api.RegOpenKey(k, svc)
        try:
            deps, typ = win32api.RegQueryValueEx(sk, "DependOnService")
        except win32api.error:
            deps = ()
        for dep in deps:
            dep = dep.lower()
            dep_on = dict.get(dep, [])
            dep_on.append(svc)
            dict[dep] = dep_on

    return __ResolveDeps(findName, dict)
Exemplo n.º 2
0
def recurse_delete_key(path, base=win32con.HKEY_CLASSES_ROOT):
    """Recursively delete registry keys.

    This is needed since you can't blast a key when subkeys exist.
    """
    try:
        h = win32api.RegOpenKey(base, path)
    except win32api.error as xxx_todo_changeme2:
        (code, fn, msg) = xxx_todo_changeme2.args
        if code != winerror.ERROR_FILE_NOT_FOUND:
            raise win32api.error(code, fn, msg)
    else:
        # parent key found and opened successfully. do some work, making sure
        # to always close the thing (error or no).
        try:
            # remove all of the subkeys
            while True:
                try:
                    subkeyname = win32api.RegEnumKey(h, 0)
                except win32api.error as xxx_todo_changeme:
                    (code, fn, msg) = xxx_todo_changeme.args
                    if code != winerror.ERROR_NO_MORE_ITEMS:
                        raise win32api.error(code, fn, msg)
                    break
                recurse_delete_key(path + '\\' + subkeyname, base)

            # remove the parent key
            _remove_key(path, base)
        finally:
            win32api.RegCloseKey(h)
Exemplo n.º 3
0
 def GetSubList(self):
     # Explicit lookup in the registry.
     ret = []
     key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "TypeLib")
     win32ui.DoWaitCursor(1)
     try:
         num = 0
         while True:
             try:
                 keyName = win32api.RegEnumKey(key, num)
             except win32api.error:
                 break
             # Enumerate all version info
             subKey = win32api.RegOpenKey(key, keyName)
             name = None
             try:
                 subNum = 0
                 bestVersion = 0.0
                 while True:
                     try:
                         versionStr = win32api.RegEnumKey(subKey, subNum)
                     except win32api.error:
                         break
                     try:
                         versionFlt = float(versionStr)
                     except ValueError:
                         versionFlt = 0  # ????
                     if versionFlt > bestVersion:
                         bestVersion = versionFlt
                         name = win32api.RegQueryValue(subKey, versionStr)
                     subNum = subNum + 1
             finally:
                 win32api.RegCloseKey(subKey)
             if name is not None:
                 ret.append(
                     HLIRegisteredTypeLibrary((keyName, versionStr), name))
             num = num + 1
     finally:
         win32api.RegCloseKey(key)
         win32ui.DoWaitCursor(0)
     ret.sort()
     return ret
Exemplo n.º 4
0
def CheckPythonPaths(verbose):
    if verbose:
        print("Python Paths:")
    # Check the core path
    if verbose:
        print("\tCore Path:", end=' ')
    try:
        appPath = win32api.RegQueryValue(
            regutil.GetRootKey(),
            regutil.BuildDefaultPythonKey() + "\\PythonPath")
    except win32api.error as exc:
        print("** does not exist - ", exc.strerror)
    problem = CheckPathString(appPath)
    if problem:
        print(problem)
    else:
        if verbose:
            print(appPath)

    key = win32api.RegOpenKey(regutil.GetRootKey(),
                              regutil.BuildDefaultPythonKey() + "\\PythonPath",
                              0, win32con.KEY_READ)
    try:
        keyNo = 0
        while True:
            try:
                appName = win32api.RegEnumKey(key, keyNo)
                appPath = win32api.RegQueryValue(key, appName)
                if verbose:
                    print("\t" + appName + ":", end=' ')
                if appPath:
                    problem = CheckPathString(appPath)
                    if problem:
                        print(problem)
                    else:
                        if verbose:
                            print(appPath)
                else:
                    if verbose:
                        print("(empty)")
                keyNo = keyNo + 1
            except win32api.error:
                break
    finally:
        win32api.RegCloseKey(key)
Exemplo n.º 5
0
def EnumKeys(root):
    index = 0
    ret = []
    while True:
        try:
            item = win32api.RegEnumKey(root, index)
        except win32api.error:
            break
        try:
            # Note this doesn't handle REG_EXPAND_SZ, but the implementation
            # here doesn't need to - that is handled as the data is read.
            val = win32api.RegQueryValue(root, item)
        except win32api.error:
            val = ""  # code using this assumes a string.

        ret.append((item, val))
        index = index + 1
    return ret
Exemplo n.º 6
0
def _GetServiceShortName(longName):
    # looks up a services name
    # from the display name
    # Thanks to Andy McKay for this code.
    access = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
    hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE,
                               "SYSTEM\\CurrentControlSet\\Services", 0,
                               access)
    num = win32api.RegQueryInfoKey(hkey)[0]
    longName = longName.lower()
    # loop through number of subkeys
    for x in range(0, num):
        # find service name, open subkey
        svc = win32api.RegEnumKey(hkey, x)
        skey = win32api.RegOpenKey(hkey, svc, 0, access)
        try:
            # find display name
            thisName = str(win32api.RegQueryValueEx(skey, "DisplayName")[0])
            if thisName.lower() == longName:
                return svc
        except win32api.error:
            # in case there is no key called DisplayName
            pass
    return None
Exemplo n.º 7
0
def CheckHelpFiles(verbose):
    if verbose:
        print("Help Files:")
    try:
        key = win32api.RegOpenKey(regutil.GetRootKey(),
                                  regutil.BuildDefaultPythonKey() + "\\Help",
                                  0, win32con.KEY_READ)
    except win32api.error as exc:
        import winerror
        if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
            raise
        return

    try:
        keyNo = 0
        while True:
            try:
                helpDesc = win32api.RegEnumKey(key, keyNo)
                helpFile = win32api.RegQueryValue(key, helpDesc)
                if verbose:
                    print("\t" + helpDesc + ":", end=' ')
                # query the os section.
                try:
                    os.stat(helpFile)
                    if verbose:
                        print(helpFile)
                except os.error:
                    print("** Help file %s does not exist" % helpFile)
                keyNo = keyNo + 1
            except win32api.error as exc:
                import winerror
                if exc.winerror != winerror.ERROR_NO_MORE_ITEMS:
                    raise
                break
    finally:
        win32api.RegCloseKey(key)
Exemplo n.º 8
0
 def GetSubList(self):
     clsidstr, versionStr = self.myobject
     collected = []
     helpPath = ""
     key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT,
                               "TypeLib\\%s\\%s" % (clsidstr, versionStr))
     win32ui.DoWaitCursor(1)
     try:
         num = 0
         while True:
             try:
                 subKey = win32api.RegEnumKey(key, num)
             except win32api.error:
                 break
             hSubKey = win32api.RegOpenKey(key, subKey)
             try:
                 value, typ = win32api.RegQueryValueEx(hSubKey, None)
                 if typ == win32con.REG_EXPAND_SZ:
                     value = win32api.ExpandEnvironmentStrings(value)
             except win32api.error:
                 value = ""
             if subKey == "HELPDIR":
                 helpPath = value
             elif subKey == "Flags":
                 flags = value
             else:
                 try:
                     lcid = int(subKey)
                     lcidkey = win32api.RegOpenKey(key, subKey)
                     # Enumerate the platforms
                     lcidnum = 0
                     while True:
                         try:
                             platform = win32api.RegEnumKey(
                                 lcidkey, lcidnum)
                         except win32api.error:
                             break
                         try:
                             hplatform = win32api.RegOpenKey(
                                 lcidkey, platform)
                             fname, typ = win32api.RegQueryValueEx(
                                 hplatform, None)
                             if typ == win32con.REG_EXPAND_SZ:
                                 fname = win32api.ExpandEnvironmentStrings(
                                     fname)
                         except win32api.error:
                             fname = ""
                         collected.append((lcid, platform, fname))
                         lcidnum = lcidnum + 1
                     win32api.RegCloseKey(lcidkey)
                 except ValueError:
                     pass
             num = num + 1
     finally:
         win32ui.DoWaitCursor(0)
         win32api.RegCloseKey(key)
     # Now, loop over my collected objects, adding a TypeLib and a HelpFile
     ret = []
     #               if helpPath: ret.append(browser.MakeHLI(helpPath, "Help Path"))
     ret.append(HLICLSID(clsidstr))
     for lcid, platform, fname in collected:
         extraDescs = []
         if platform != "win32":
             extraDescs.append(platform)
         if lcid:
             extraDescs.append("locale=%s" % lcid)
         extraDesc = ""
         if extraDescs:
             extraDesc = " (%s)" % ", ".join(extraDescs)
         ret.append(HLITypeLib(fname, "Type Library" + extraDesc))
     ret.sort()
     return ret