Python winreg 模块,KEY_ALL_ACCESS 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用winreg.KEY_ALL_ACCESS

项目:paste2box    作者:rokups    | 项目源码 | 文件源码
def is_autostart_enabled(self):
        if os.name == 'nt':
            with winreg.OpenKey(winreg.HKEY_CURRENT_USER, self._windows_run_reg_key, 0, winreg.KEY_ALL_ACCESS) as key:
                try:
                    reg_value, reg_type = winreg.QueryValueEx(key, const.APP_NAME)
                    if reg_type == winreg.REG_SZ and reg_value == self._get_executable_path():
                        return True
                    else:
                        try:
                            winreg.DeleteValue(key, self.WIN_REG_AUTORUN_KEY)
                        except OSError:
                            pass        # key does not exist
                except:
                    return False
        else:
            return os.path.exists(self._linux_autostart_file)
项目:depot_tools    作者:webrtc-uwp    | 项目源码 | 文件源码
def EnableCrashDumpCollection():
  """Tell Windows Error Reporting to record crash dumps so that we can diagnose
  linker crashes and other toolchain failures. Documented at:
  https://msdn.microsoft.com/en-us/library/windows/desktop/bb787181.aspx
  """
  if sys.platform == 'win32' and os.environ.get('CHROME_HEADLESS') == '1':
    key_name = r'SOFTWARE\Microsoft\Windows\Windows Error Reporting'
    try:
      key = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, key_name, 0,
                               winreg.KEY_WOW64_64KEY | winreg.KEY_ALL_ACCESS)
      # Merely creating LocalDumps is sufficient to enable the defaults.
      winreg.CreateKey(key, "LocalDumps")
      # Disable the WER UI, as documented here:
      # https://msdn.microsoft.com/en-us/library/windows/desktop/bb513638.aspx
      winreg.SetValueEx(key, "DontShowUI", 0, winreg.REG_DWORD, 1)
    # Trap OSError instead of WindowsError so pylint will succeed on Linux.
    # Catching errors is important because some build machines are not elevated
    # and writing to HKLM requires elevation.
    except OSError:
      pass
项目:keyrings.alt    作者:jaraco    | 项目源码 | 文件源码
def _delete_key_if_empty(self, service):
        key_name = r'Software\%s\Keyring' % service
        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_name, 0,
            winreg.KEY_ALL_ACCESS)
        try:
            winreg.EnumValue(key, 0)
            return
        except WindowsError:
            pass
        winreg.CloseKey(key)

        # it's empty; delete everything
        while key_name != 'Software':
            parent, sep, base = key_name.rpartition('\\')
            key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, parent, 0,
                winreg.KEY_ALL_ACCESS)
            winreg.DeleteKey(key, base)
            winreg.CloseKey(key)
            key_name = parent
项目:paste2box    作者:rokups    | 项目源码 | 文件源码
def _save_autostart_win(self, on):
        with winreg.OpenKey(winreg.HKEY_CURRENT_USER, self._windows_run_reg_key, 0, winreg.KEY_ALL_ACCESS) as key:
            if on:
                winreg.SetValueEx(key, const.APP_NAME, 0, winreg.REG_SZ, self._get_executable_path())
            else:
                try:
                    winreg.DeleteValue(key, const.APP_NAME)
                except OSError:
                    pass        # key does not exist
项目:pyVirtualize    作者:rocky1109    | 项目源码 | 文件源码
def setenv(self, name, value):
        # Note: for 'system' scope, you must run this as Administrator
        key = winreg.OpenKey(self.root, self.subkey, 0, winreg.KEY_ALL_ACCESS)
        winreg.SetValueEx(key, name, 0, winreg.REG_EXPAND_SZ, value)
        winreg.CloseKey(key)
        # For some strange reason, calling SendMessage from the current process
        # doesn't propagate environment changes at all.
        # TODO: handle CalledProcessError (for assert)
        check_call('''\
"%s" -c "import win32api, win32con; assert win32api.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment')"''' % sys.executable)
项目:bingLockScreen    作者:WeiqiChenCN    | 项目源码 | 文件源码
def set_up_windows_7_oem_background_reg():
    mid_key_str = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI\\Background'
    target_key_name = 'OEMBackground'
    top_key = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, mid_key_str,
                                 access=winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY)
    winreg.SetValueEx(top_key, target_key_name, 0, winreg.REG_DWORD, 1)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def setEnvironment(scope, name, value):
    assert scope in ('user', 'system')
    #INFO_MSG('set environment: name=%s, value=%s' % (name, value))

    if platform.system() == 'Windows':
        root, subkey = getWindowsEnvironmentKey(scope)
        # Note: for 'system' scope, you must run this as Administrator
        key = winreg.OpenKey(root, subkey, 0, winreg.KEY_ALL_ACCESS)
        winreg.SetValueEx(key, name, 0, winreg.REG_EXPAND_SZ, value)
        winreg.CloseKey(key)
    else:
        if name.lower() == 'uid':
            uid, username = value
            if uid != str(os.geteuid()):
                ret, cret = syscommand('bash -c \'usermod -d /home/%s/ -u %s %s\'' % (pwd.getpwnam(username).pw_dir, uid, username), True)
                INFO_MSG(ret)
                INFO_MSG(cret)
            return

        userhome = "~"
        if len(os_user_name) > 0:
            userhome = pwd.getpwnam(os_user_name).pw_dir 

        f = open('%s/.bashrc' % userhome, 'a')
        f.write("export %s=%s\n\n" % (name, value))
        f.close()

        if os.geteuid() > 0:
            syscommand('bash -c \'source %s/.bashrc\'' % userhome, False)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def remmoveEnvironment(scope, name):
    assert scope in ('user', 'system')

    if platform.system() == 'Windows':
        root, subkey = getWindowsEnvironmentKey(scope)
        key = winreg.OpenKey(root, subkey, 0, winreg.KEY_ALL_ACCESS)

        try:
            winreg.DeleteValue(key, name)
        except WindowsError:
            pass
    else:
        removeLinuxEnvironment(scope, name)
项目:keyrings.alt    作者:jaraco    | 项目源码 | 文件源码
def delete_password(self, service, username):
        """Delete the password for the username of the service.
        """
        try:
            key_name = r'Software\%s\Keyring' % service
            hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_name, 0,
                winreg.KEY_ALL_ACCESS)
            winreg.DeleteValue(hkey, username)
            winreg.CloseKey(hkey)
        except WindowsError:
            e = sys.exc_info()[1]
            raise PasswordDeleteError(e)
        self._delete_key_if_empty(service)
项目:persepolis    作者:persepolisdm    | 项目源码 | 文件源码
def checkstartup():
    # check if it is linux
    if os_type == "Linux" or os_type == "FreeBSD" or os_type == 'OpenBSD':
        # check if the startup exists
        if os.path.exists(home_address + "/.config/autostart/persepolis.desktop"):
            return True
        else:
            return False

    # check if it is mac
    elif os_type == "Darwin":
        # OS X
        if os.path.exists(home_address + "/Library/LaunchAgents/com.persepolisdm.plist"):
            return True
        else:
            return False

    # check if it is Windows
    elif os_type == "Windows":
        # try to open startup key and check persepolis value
        try:
            aKey = winreg.OpenKey(
                winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, winreg.KEY_ALL_ACCESS)
            startupvalue = winreg.QueryValueEx(aKey, 'persepolis')
            startup = True
        except WindowsError:
            startup = False

        # Close the connection
        winreg.CloseKey(aKey)

        # if the startup enabled or disabled
        if startup:
            return True
        if not startup:
            return False

# add startup file
项目:persepolis    作者:persepolisdm    | 项目源码 | 文件源码
def removestartup():
    # check if it is linux
    if os_type == 'Linux' or os_type == 'FreeBSD' or os_type == 'OpenBSD':

        # remove it
        os.remove(home_address + "/.config/autostart/persepolis.desktop")

    # check if it is mac OS
    elif os_type == "Darwin":
        # OS X
        if checkstartup():
            os.system('launchctl unload ' + home_address +
                      "/Library/LaunchAgents/com.persepolisdm.plist")
            os.remove(home_address +
                      "/Library/LaunchAgents/com.persepolisdm.plist")

    # check if it is Windows
    elif os_type == 'Windows':
        if checkstartup():
            # Connect to the startup path in Registry
            key = winreg.OpenKey(
                winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, winreg.KEY_ALL_ACCESS)

            # remove persepolis from startup
            winreg.DeleteValue(key, 'persepolis')

            # Close connection
            winreg.CloseKey(key)
项目:BingNiceWallpapers    作者:redstoneleo    | 项目源码 | 文件源码
def get_runonce():
        return winreg.OpenKey(_registry,
                              r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0,
                              winreg.KEY_ALL_ACCESS)