Python win32api 模块,RegQueryValue() 实例源码

我们从Python开源项目中,提取了以下46个代码示例,用于说明如何使用win32api.RegQueryValue()

项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def EnumKeys(root):
    index = 0
    ret = []
    while 1:
        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
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def IIDToInterfaceName(iid):
    """Converts an IID to a string interface name.  

    Used primarily for debugging purposes, this allows a cryptic IID to
    be converted to a useful string name.  This will firstly look for interfaces
    known (ie, registered) by pythoncom.  If not known, it will look in the
    registry for a registered interface.

    iid -- An IID object.

    Result -- Always a string - either an interface name, or '<Unregistered interface>'
    """
    try:
        return pythoncom.ServerInterfaces[iid]
    except KeyError:
        try:
            try:
                return win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT, "Interface\\%s" % iid)
            except win32api.error:
                pass
        except ImportError:
            pass
        return str(iid)
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def EnumKeys(root):
    index = 0
    ret = []
    while 1:
        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
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def IIDToInterfaceName(iid):
    """Converts an IID to a string interface name.  

    Used primarily for debugging purposes, this allows a cryptic IID to
    be converted to a useful string name.  This will firstly look for interfaces
    known (ie, registered) by pythoncom.  If not known, it will look in the
    registry for a registered interface.

    iid -- An IID object.

    Result -- Always a string - either an interface name, or '<Unregistered interface>'
    """
    try:
        return pythoncom.ServerInterfaces[iid]
    except KeyError:
        try:
            try:
                return win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT, "Interface\\%s" % iid)
            except win32api.error:
                pass
        except ImportError:
            pass
        return str(iid)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def EnumKeys(root):
    index = 0
    ret = []
    while 1:
        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
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def IIDToInterfaceName(iid):
    """Converts an IID to a string interface name.  

    Used primarily for debugging purposes, this allows a cryptic IID to
    be converted to a useful string name.  This will firstly look for interfaces
    known (ie, registered) by pythoncom.  If not known, it will look in the
    registry for a registered interface.

    iid -- An IID object.

    Result -- Always a string - either an interface name, or '<Unregistered interface>'
    """
    try:
        return pythoncom.ServerInterfaces[iid]
    except KeyError:
        try:
            try:
                return win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT, "Interface\\%s" % iid)
            except win32api.error:
                pass
        except ImportError:
            pass
        return str(iid)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def EnumKeys(root):
    index = 0
    ret = []
    while 1:
        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
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def IIDToInterfaceName(iid):
    """Converts an IID to a string interface name.  

    Used primarily for debugging purposes, this allows a cryptic IID to
    be converted to a useful string name.  This will firstly look for interfaces
    known (ie, registered) by pythoncom.  If not known, it will look in the
    registry for a registered interface.

    iid -- An IID object.

    Result -- Always a string - either an interface name, or '<Unregistered interface>'
    """
    try:
        return pythoncom.ServerInterfaces[iid]
    except KeyError:
        try:
            try:
                return win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT, "Interface\\%s" % iid)
            except win32api.error:
                pass
        except ImportError:
            pass
        return str(iid)
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def CheckRegisteredExe(exename):
    try:
        os.stat(win32api.RegQueryValue(regutil.GetRootKey()  , regutil.GetAppPathsKey() + "\\" + exename))
#   except SystemError:
    except (os.error,win32api.error):
        print "Registration of %s - Not registered correctly" % exename
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def CheckPythonPaths(verbose):
    if verbose: print "Python Paths:"
    # Check the core path
    if verbose: print "\tCore Path:",
    try:
        appPath = win32api.RegQueryValue(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath")
    except win32api.error, 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 1:
            try:
                appName = win32api.RegEnumKey(key, keyNo)
                appPath = win32api.RegQueryValue(key, appName)
                if verbose: print "\t"+appName+":",
                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)
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def CheckHelpFiles(verbose):
    if verbose: print "Help Files:"
    try:
        key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
    except win32api.error, exc:
        import winerror
        if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
            raise
        return

    try:
        keyNo = 0
        while 1:
            try:
                helpDesc = win32api.RegEnumKey(key, keyNo)
                helpFile = win32api.RegQueryValue(key, helpDesc)
                if verbose: print "\t"+helpDesc+":",
                # 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, exc:
                import winerror
                if exc.winerror!=winerror.ERROR_NO_MORE_ITEMS:
                    raise
                break
    finally:
        win32api.RegCloseKey(key)
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def GetRegistryDefaultValue(subkey, rootkey = None):
    """A helper to return the default value for a key in the registry.
        """
    if rootkey is None: rootkey = GetRootKey()
    return win32api.RegQueryValue(rootkey, subkey)
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def GetRegisteredExe(exeAlias):
    """Get a registered .exe
    """
    return win32api.RegQueryValue(GetRootKey(), GetAppPathsKey() + "\\" + exeAlias)
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def LocatePythonServiceExe(exeName = None):
    if not exeName and hasattr(sys, "frozen"):
        # If py2exe etc calls this with no exeName, default is current exe.
        return sys.executable

    # Try and find the specified EXE somewhere.  If specifically registered,
    # use it.  Otherwise look down sys.path, and the global PATH environment.
    if exeName is None:
        if os.path.splitext(win32service.__file__)[0].endswith("_d"):
            exeName = "PythonService_d.exe"
        else:
            exeName = "PythonService.exe"
    # See if it exists as specified
    if os.path.isfile(exeName): return win32api.GetFullPathName(exeName)
    baseName = os.path.splitext(os.path.basename(exeName))[0]
    try:
        exeName = win32api.RegQueryValue(win32con.HKEY_LOCAL_MACHINE,
                                         "Software\\Python\\%s\\%s" % (baseName, sys.winver))
        if os.path.isfile(exeName):
            return exeName
        raise RuntimeError("The executable '%s' is registered as the Python " \
                           "service exe, but it does not exist as specified" \
                           % exeName)
    except win32api.error:
        # OK - not there - lets go a-searchin'
        for path in [sys.prefix] + sys.path:
            look = os.path.join(path, exeName)
            if os.path.isfile(look):
                return win32api.GetFullPathName(look)
        # Try the global Path.
        try:
            return win32api.SearchPath(None, exeName)[0]
        except win32api.error:
            msg = "%s is not correctly registered\nPlease locate and run %s, and it will self-register\nThen run this service registration process again." % (exeName, exeName)
            raise error(msg)
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def CreateInstance(clsid, reqIID):
  """Create a new instance of the specified IID

  The COM framework **always** calls this function to create a new 
  instance for the specified CLSID.  This function looks up the
  registry for the name of a policy, creates the policy, and asks the
  policy to create the specified object by calling the _CreateInstance_ method.

  Exactly how the policy creates the instance is up to the policy.  See the
  specific policy documentation for more details.
  """
  # First see is sys.path should have something on it.
  try:
    addnPaths = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regAddnPath % clsid).split(';')
    for newPath in addnPaths:
      if newPath not in sys.path:
        sys.path.insert(0, newPath)
  except win32api.error:
    pass
  try:
    policy = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regPolicy % clsid)
    policy = resolve_func(policy)
  except win32api.error:
    policy = DefaultPolicy

  try:
    dispatcher = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regDispatcher % clsid)
    if dispatcher: dispatcher = resolve_func(dispatcher)
  except win32api.error:
    dispatcher = None

  if dispatcher:
    retObj = dispatcher(policy, None)
  else:
    retObj = policy(None)
  return retObj._CreateInstance_(clsid, reqIID)
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def _get_string(path, base=win32con.HKEY_CLASSES_ROOT):
  "Get a string value from the registry."

  try:
    return win32api.RegQueryValue(base, path)
  except win32api.error:
    return None
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def _find_localserver_exe(mustfind):
  if not sys.platform.startswith("win32"):
    return sys.executable
  if pythoncom.__file__.find("_d") < 0:
    exeBaseName = "pythonw.exe"
  else:
    exeBaseName = "pythonw_d.exe"
  # First see if in the same directory as this .EXE
  exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix directory
    exeName = os.path.join( sys.prefix, exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix/pcbuild directory (for developers)
    if "64 bit" in sys.version:
      exeName = os.path.join( sys.prefix, "PCbuild",  "amd64", exeBaseName )
    else:
      exeName = os.path.join( sys.prefix, "PCbuild",  exeBaseName )
  if not os.path.exists(exeName):
    # See if the registry has some info.
    try:
      key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
      path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
      exeName = os.path.join( path, exeBaseName )
    except (AttributeError,win32api.error):
      pass
  if not os.path.exists(exeName):
    if mustfind:
      raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
    return None
  return exeName
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def GetSubList(self):
        # Explicit lookup in the registry.
        ret = []
        key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "TypeLib")
        win32ui.DoWaitCursor(1)
        try:
            num = 0
            while 1:
                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 1:
                        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
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def CreateInstance(clsid, reqIID):
  """Create a new instance of the specified IID

  The COM framework **always** calls this function to create a new 
  instance for the specified CLSID.  This function looks up the
  registry for the name of a policy, creates the policy, and asks the
  policy to create the specified object by calling the _CreateInstance_ method.

  Exactly how the policy creates the instance is up to the policy.  See the
  specific policy documentation for more details.
  """
  # First see is sys.path should have something on it.
  try:
    addnPaths = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regAddnPath % clsid).split(';')
    for newPath in addnPaths:
      if newPath not in sys.path:
        sys.path.insert(0, newPath)
  except win32api.error:
    pass
  try:
    policy = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regPolicy % clsid)
    policy = resolve_func(policy)
  except win32api.error:
    policy = DefaultPolicy

  try:
    dispatcher = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regDispatcher % clsid)
    if dispatcher: dispatcher = resolve_func(dispatcher)
  except win32api.error:
    dispatcher = None

  if dispatcher:
    retObj = dispatcher(policy, None)
  else:
    retObj = policy(None)
  return retObj._CreateInstance_(clsid, reqIID)
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def _get_string(path, base=win32con.HKEY_CLASSES_ROOT):
  "Get a string value from the registry."

  try:
    return win32api.RegQueryValue(base, path)
  except win32api.error:
    return None
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def _find_localserver_exe(mustfind):
  if not sys.platform.startswith("win32"):
    return sys.executable
  if pythoncom.__file__.find("_d") < 0:
    exeBaseName = "pythonw.exe"
  else:
    exeBaseName = "pythonw_d.exe"
  # First see if in the same directory as this .EXE
  exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix directory
    exeName = os.path.join( sys.prefix, exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix/pcbuild directory (for developers)
    if "64 bit" in sys.version:
      exeName = os.path.join( sys.prefix, "PCbuild",  "amd64", exeBaseName )
    else:
      exeName = os.path.join( sys.prefix, "PCbuild",  exeBaseName )
  if not os.path.exists(exeName):
    # See if the registry has some info.
    try:
      key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
      path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
      exeName = os.path.join( path, exeBaseName )
    except (AttributeError,win32api.error):
      pass
  if not os.path.exists(exeName):
    if mustfind:
      raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
    return None
  return exeName
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def GetSubList(self):
        # Explicit lookup in the registry.
        ret = []
        key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "TypeLib")
        win32ui.DoWaitCursor(1)
        try:
            num = 0
            while 1:
                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 1:
                        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
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def FindPythonExe(exeAlias, possibleRealNames, searchPaths):
    """Find an exe.

       Returns the full path to the .exe, and a boolean indicating if the current
       registered entry is OK.  We don't trust the already registered version even
       if it exists - it may be wrong (ie, for a different Python version)
    """
    import win32api, regutil, string, os, sys
    if possibleRealNames is None:
        possibleRealNames = exeAlias
    # Look first in Python's home.
    found = os.path.join(sys.prefix,  possibleRealNames)
    if not FileExists(found): # for developers
        if "64 bit" in sys.version:
            found = os.path.join(sys.prefix,  "PCBuild", "amd64", possibleRealNames)
        else:
            found = os.path.join(sys.prefix,  "PCBuild", possibleRealNames)
    if not FileExists(found):
        found = LocateFileName(possibleRealNames, searchPaths)

    registered_ok = 0
    try:
        registered = win32api.RegQueryValue(regutil.GetRootKey(), regutil.GetAppPathsKey() + "\\" + exeAlias)
        registered_ok = found==registered
    except win32api.error:
        pass
    return found, registered_ok
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def CheckRegisteredExe(exename):
    try:
        os.stat(win32api.RegQueryValue(regutil.GetRootKey()  , regutil.GetAppPathsKey() + "\\" + exename))
#   except SystemError:
    except (os.error,win32api.error):
        print "Registration of %s - Not registered correctly" % exename
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def CheckPythonPaths(verbose):
    if verbose: print "Python Paths:"
    # Check the core path
    if verbose: print "\tCore Path:",
    try:
        appPath = win32api.RegQueryValue(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath")
    except win32api.error, 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 1:
            try:
                appName = win32api.RegEnumKey(key, keyNo)
                appPath = win32api.RegQueryValue(key, appName)
                if verbose: print "\t"+appName+":",
                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)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def CheckHelpFiles(verbose):
    if verbose: print "Help Files:"
    try:
        key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
    except win32api.error, exc:
        import winerror
        if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
            raise
        return

    try:
        keyNo = 0
        while 1:
            try:
                helpDesc = win32api.RegEnumKey(key, keyNo)
                helpFile = win32api.RegQueryValue(key, helpDesc)
                if verbose: print "\t"+helpDesc+":",
                # 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, exc:
                import winerror
                if exc.winerror!=winerror.ERROR_NO_MORE_ITEMS:
                    raise
                break
    finally:
        win32api.RegCloseKey(key)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def GetRegistryDefaultValue(subkey, rootkey = None):
    """A helper to return the default value for a key in the registry.
        """
    if rootkey is None: rootkey = GetRootKey()
    return win32api.RegQueryValue(rootkey, subkey)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def GetRegisteredNamedPath(name):
    """Get a registered named path, or None if it doesnt exist.
    """
    keyStr = BuildDefaultPythonKey() + "\\PythonPath"
    if name: keyStr = keyStr + "\\" + name
    try:
        return win32api.RegQueryValue(GetRootKey(), keyStr)
    except win32api.error, exc:
        import winerror
        if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
            raise
        return None
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def _ListAllHelpFilesInRoot(root):
    """Returns a list of (helpDesc, helpFname) for all registered help files
    """
    import regutil
    retList = []
    try:
        key = win32api.RegOpenKey(root, regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
    except win32api.error, exc:
        import winerror
        if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
            raise
        return retList
    try:
        keyNo = 0
        while 1:
            try:
                helpDesc = win32api.RegEnumKey(key, keyNo)
                helpFile = win32api.RegQueryValue(key, helpDesc)
                retList.append((helpDesc, helpFile))
                keyNo = keyNo + 1
            except win32api.error, exc:
                import winerror
                if exc.winerror!=winerror.ERROR_NO_MORE_ITEMS:
                    raise
                break
    finally:
        win32api.RegCloseKey(key)
    return retList
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def FindTabNanny():
    try:
        return __import__("tabnanny")
    except ImportError:
        pass
    # OK - not in the standard library - go looking.
    filename = "tabnanny.py"
    try:
        path = win32api.RegQueryValue(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % (sys.winver))
    except win32api.error:
        print "WARNING - The Python registry does not have an 'InstallPath' setting"
        print "          The file '%s' can not be located" % (filename)
        return None
    fname = os.path.join(path, "Tools\\Scripts\\%s" % filename)
    try:
        os.stat(fname)
    except os.error:
        print "WARNING - The file '%s' can not be located in path '%s'" % (filename, path)
        return None

    tabnannyhome, tabnannybase = os.path.split(fname)
    tabnannybase = os.path.splitext(tabnannybase)[0]
    # Put tab nanny at the top of the path.
    sys.path.insert(0, tabnannyhome)
    try:
        return __import__(tabnannybase)
    finally:
        # remove the tab-nanny from the path
        del sys.path[0]
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def CreateInstance(clsid, reqIID):
  """Create a new instance of the specified IID

  The COM framework **always** calls this function to create a new 
  instance for the specified CLSID.  This function looks up the
  registry for the name of a policy, creates the policy, and asks the
  policy to create the specified object by calling the _CreateInstance_ method.

  Exactly how the policy creates the instance is up to the policy.  See the
  specific policy documentation for more details.
  """
  # First see is sys.path should have something on it.
  try:
    addnPaths = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regAddnPath % clsid).split(';')
    for newPath in addnPaths:
      if newPath not in sys.path:
        sys.path.insert(0, newPath)
  except win32api.error:
    pass
  try:
    policy = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regPolicy % clsid)
    policy = resolve_func(policy)
  except win32api.error:
    policy = DefaultPolicy

  try:
    dispatcher = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regDispatcher % clsid)
    if dispatcher: dispatcher = resolve_func(dispatcher)
  except win32api.error:
    dispatcher = None

  if dispatcher:
    retObj = dispatcher(policy, None)
  else:
    retObj = policy(None)
  return retObj._CreateInstance_(clsid, reqIID)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def _get_string(path, base=win32con.HKEY_CLASSES_ROOT):
  "Get a string value from the registry."

  try:
    return win32api.RegQueryValue(base, path)
  except win32api.error:
    return None
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def _find_localserver_exe(mustfind):
  if not sys.platform.startswith("win32"):
    return sys.executable
  if pythoncom.__file__.find("_d") < 0:
    exeBaseName = "pythonw.exe"
  else:
    exeBaseName = "pythonw_d.exe"
  # First see if in the same directory as this .EXE
  exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix directory
    exeName = os.path.join( sys.prefix, exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix/pcbuild directory (for developers)
    if "64 bit" in sys.version:
      exeName = os.path.join( sys.prefix, "PCbuild",  "amd64", exeBaseName )
    else:
      exeName = os.path.join( sys.prefix, "PCbuild",  exeBaseName )
  if not os.path.exists(exeName):
    # See if the registry has some info.
    try:
      key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
      path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
      exeName = os.path.join( path, exeBaseName )
    except (AttributeError,win32api.error):
      pass
  if not os.path.exists(exeName):
    if mustfind:
      raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
    return None
  return exeName
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def GetSubList(self):
        # Explicit lookup in the registry.
        ret = []
        key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "TypeLib")
        win32ui.DoWaitCursor(1)
        try:
            num = 0
            while 1:
                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 1:
                        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
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def _ListAllHelpFilesInRoot(root):
    """Returns a list of (helpDesc, helpFname) for all registered help files
    """
    import regutil
    retList = []
    try:
        key = win32api.RegOpenKey(root, regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
    except win32api.error as exc:
        import winerror
        if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
            raise
        return retList
    try:
        keyNo = 0
        while 1:
            try:
                helpDesc = win32api.RegEnumKey(key, keyNo)
                helpFile = win32api.RegQueryValue(key, helpDesc)
                retList.append((helpDesc, 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)
    return retList
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def FindTabNanny():
    try:
        return __import__("tabnanny")
    except ImportError:
        pass
    # OK - not in the standard library - go looking.
    filename = "tabnanny.py"
    try:
        path = win32api.RegQueryValue(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % (sys.winver))
    except win32api.error:
        print("WARNING - The Python registry does not have an 'InstallPath' setting")
        print("          The file '%s' can not be located" % (filename))
        return None
    fname = os.path.join(path, "Tools\\Scripts\\%s" % filename)
    try:
        os.stat(fname)
    except os.error:
        print("WARNING - The file '%s' can not be located in path '%s'" % (filename, path))
        return None

    tabnannyhome, tabnannybase = os.path.split(fname)
    tabnannybase = os.path.splitext(tabnannybase)[0]
    # Put tab nanny at the top of the path.
    sys.path.insert(0, tabnannyhome)
    try:
        return __import__(tabnannybase)
    finally:
        # remove the tab-nanny from the path
        del sys.path[0]
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def FindPythonExe(exeAlias, possibleRealNames, searchPaths):
    """Find an exe.

       Returns the full path to the .exe, and a boolean indicating if the current
       registered entry is OK.  We don't trust the already registered version even
       if it exists - it may be wrong (ie, for a different Python version)
    """
    import win32api, regutil, string, os, sys
    if possibleRealNames is None:
        possibleRealNames = exeAlias
    # Look first in Python's home.
    found = os.path.join(sys.prefix,  possibleRealNames)
    if not FileExists(found): # for developers
        if "64 bit" in sys.version:
            found = os.path.join(sys.prefix,  "PCBuild", "amd64", possibleRealNames)
        else:
            found = os.path.join(sys.prefix,  "PCBuild", possibleRealNames)
    if not FileExists(found):
        found = LocateFileName(possibleRealNames, searchPaths)

    registered_ok = 0
    try:
        registered = win32api.RegQueryValue(regutil.GetRootKey(), regutil.GetAppPathsKey() + "\\" + exeAlias)
        registered_ok = found==registered
    except win32api.error:
        pass
    return found, registered_ok
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
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 1:
            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)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
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 1:
            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)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def GetRegistryDefaultValue(subkey, rootkey = None):
    """A helper to return the default value for a key in the registry.
        """
    if rootkey is None: rootkey = GetRootKey()
    return win32api.RegQueryValue(rootkey, subkey)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def GetRegisteredExe(exeAlias):
    """Get a registered .exe
    """
    return win32api.RegQueryValue(GetRootKey(), GetAppPathsKey() + "\\" + exeAlias)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def GetRegisteredNamedPath(name):
    """Get a registered named path, or None if it doesnt exist.
    """
    keyStr = BuildDefaultPythonKey() + "\\PythonPath"
    if name: keyStr = keyStr + "\\" + name
    try:
        return win32api.RegQueryValue(GetRootKey(), keyStr)
    except win32api.error as exc:
        import winerror
        if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
            raise
        return None
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def CreateInstance(clsid, reqIID):
  """Create a new instance of the specified IID

  The COM framework **always** calls this function to create a new 
  instance for the specified CLSID.  This function looks up the
  registry for the name of a policy, creates the policy, and asks the
  policy to create the specified object by calling the _CreateInstance_ method.

  Exactly how the policy creates the instance is up to the policy.  See the
  specific policy documentation for more details.
  """
  # First see is sys.path should have something on it.
  try:
    addnPaths = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regAddnPath % clsid).split(';')
    for newPath in addnPaths:
      if newPath not in sys.path:
        sys.path.insert(0, newPath)
  except win32api.error:
    pass
  try:
    policy = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regPolicy % clsid)
    policy = resolve_func(policy)
  except win32api.error:
    policy = DefaultPolicy

  try:
    dispatcher = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
                                      regDispatcher % clsid)
    if dispatcher: dispatcher = resolve_func(dispatcher)
  except win32api.error:
    dispatcher = None

  if dispatcher:
    retObj = dispatcher(policy, None)
  else:
    retObj = policy(None)
  return retObj._CreateInstance_(clsid, reqIID)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def _get_string(path, base=win32con.HKEY_CLASSES_ROOT):
  "Get a string value from the registry."

  try:
    return win32api.RegQueryValue(base, path)
  except win32api.error:
    return None
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def _find_localserver_exe(mustfind):
  if not sys.platform.startswith("win32"):
    return sys.executable
  if pythoncom.__file__.find("_d") < 0:
    exeBaseName = "pythonw.exe"
  else:
    exeBaseName = "pythonw_d.exe"
  # First see if in the same directory as this .EXE
  exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix directory
    exeName = os.path.join( sys.prefix, exeBaseName )
  if not os.path.exists(exeName):
    # See if in our sys.prefix/pcbuild directory (for developers)
    if "64 bit" in sys.version:
      exeName = os.path.join( sys.prefix, "PCbuild",  "amd64", exeBaseName )
    else:
      exeName = os.path.join( sys.prefix, "PCbuild",  exeBaseName )
  if not os.path.exists(exeName):
    # See if the registry has some info.
    try:
      key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
      path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
      exeName = os.path.join( path, exeBaseName )
    except (AttributeError,win32api.error):
      pass
  if not os.path.exists(exeName):
    if mustfind:
      raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
    return None
  return exeName
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def GetSubList(self):
        # Explicit lookup in the registry.
        ret = []
        key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "TypeLib")
        win32ui.DoWaitCursor(1)
        try:
            num = 0
            while 1:
                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 1:
                        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