Python winreg 模块,SetValueEx() 实例源码

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

项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def register(classobj):
    import winreg
    subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_
    try:
        hKey = winreg.CreateKey( winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
        subKey = winreg.SetValueEx( hKey, "ButtonText", 0, winreg.REG_SZ, classobj._button_text_ )
        winreg.SetValueEx( hKey, "ClsidExtension", 0, winreg.REG_SZ, classobj._reg_clsid_ ) # reg value for calling COM object
        winreg.SetValueEx( hKey, "CLSID", 0, winreg.REG_SZ, "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}" ) # CLSID for button that sends command to COM object
        winreg.SetValueEx( hKey, "Default Visible", 0, winreg.REG_SZ, "Yes" )
        winreg.SetValueEx( hKey, "ToolTip", 0, winreg.REG_SZ, classobj._tool_tip_ )
        winreg.SetValueEx( hKey, "Icon", 0, winreg.REG_SZ, classobj._icon_)
        winreg.SetValueEx( hKey, "HotIcon", 0, winreg.REG_SZ, classobj._hot_icon_)
    except WindowsError:
        print("Couldn't set standard toolbar reg keys.")
    else:
        print("Set standard toolbar reg keys.")
项目:nzb-monkey    作者:nzblnk    | 项目源码 | 文件源码
def config_win():

    try:
        import winreg as reg
        key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk')
        reg.SetValue(key, '', reg.REG_SZ, 'URL:nzblnk')
        reg.SetValueEx(key, 'URL Protocol', 0, reg.REG_SZ, '')
        reg.CloseKey(key)

        key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk\\shell\\open\\command')
        reg.SetValue(key, '', reg.REG_SZ, '"{0}" "%1"'.format(op.normpath(os.path.abspath(sys.executable))))
        reg.CloseKey(key)

    except (OSError, ImportError):
        print(Col.FAIL + ' FAILED to setup registry link for NZBLNK scheme!' + Col.OFF)
        sleep(wait_time)
        sys.exit(2)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DllRegisterServer():
    import winreg
    key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE,
                            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \
                            "Explorer\\Desktop\\Namespace\\" + \
                            ShellFolderRoot._reg_clsid_)
    winreg.SetValueEx(key, None, 0, winreg.REG_SZ, ShellFolderRoot._reg_desc_)
    # And special shell keys under our CLSID
    key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT,
                        "CLSID\\" + ShellFolderRoot._reg_clsid_ + "\\ShellFolder")
    # 'Attributes' is an int stored as a binary! use struct
    attr = shellcon.SFGAO_FOLDER | shellcon.SFGAO_HASSUBFOLDER | \
           shellcon.SFGAO_BROWSABLE
    import struct
    s = struct.pack("i", attr)
    winreg.SetValueEx(key, "Attributes", 0, winreg.REG_BINARY, s)
    print(ShellFolderRoot._reg_desc_, "registration complete.")
项目:Chromium_DepotTools    作者:p07r0457    | 项目源码 | 文件源码
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.CreateKey(winreg.HKEY_LOCAL_MACHINE, key_name)
      # 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
项目:node-gn    作者:Shouqun    | 项目源码 | 文件源码
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.CreateKey(winreg.HKEY_LOCAL_MACHINE, key_name)
      # 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
项目: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
项目:lib9    作者:Jumpscale    | 项目源码 | 文件源码
def setValueFromRegKey(self, key, valueName, valueData, valueType):
        """Sets a value in a key

        @param key: The registry key that holds the value to set. If the key does not exist, it will be created. The key should include the section. Eg. "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion"
        @type key: string
        @param valueName: The name of the value to set
        @type valueName: string
        @param valueData: The data to assign to the value
        @type valueData: string
        @param valueType: The type of the value
        @type valueType: WinRegValueType
        """
        hkey, key = self._getHiveAndKey(key)
        aReg = reg.ConnectRegistry(None, hkey)
        aKey = reg.CreateKey(aReg, key)
        reg.SetValueEx(aKey, valueName, 0, valueType.type, valueData)
项目:lib9    作者:Jumpscale    | 项目源码 | 文件源码
def addActionToShell(self, name, descr, cmd):
        """
        add action in windows explorer on top of file & dir
        """
        if descr == "":
            descr = name
        import winreg as winreg
        for item in ["*", "Directory"]:
            key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, r'%s\shell\%s' % (item, name))
            key2 = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, r'%s\shell\%s\Command' % (item, name))
            winreg.SetValueEx(key, "", None, winreg.REG_SZ, "%s " % descr)
            winreg.SetValueEx(key, "Icon", None, winreg.REG_SZ, "")
            winreg.SetValueEx(key, "Position", None, winreg.REG_SZ, "Top")
            winreg.SetValueEx(key, "", None, winreg.REG_SZ, "%s " % descr)
            #winreg.SetValueEx(key2,"",None,winreg.REG_SZ,r'cmd.exe /s /k pushd "%V"')
            winreg.SetValueEx(key2, "", None, winreg.REG_SZ, cmd)
            winreg.CloseKey(key)
项目: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)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DllRegisterServer():
    # Also need to register specially in:
    # HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches
    # See link at top of file.
    import winreg
    kn = r"Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%s" \
         % (EmptyVolumeCache._reg_desc_,)
    key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, kn)
    winreg.SetValueEx(key, None, 0, winreg.REG_SZ, EmptyVolumeCache._reg_clsid_)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DllRegisterServer():
    import winreg
    if sys.getwindowsversion()[0] < 6:
        print("This sample only works on Vista")
        sys.exit(1)

    key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE,
                            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \
                            "Explorer\\Desktop\\Namespace\\" + \
                            ShellFolder._reg_clsid_)
    winreg.SetValueEx(key, None, 0, winreg.REG_SZ, ShellFolder._reg_desc_)
    # And special shell keys under our CLSID
    key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT,
                        "CLSID\\" + ShellFolder._reg_clsid_ + "\\ShellFolder")
    # 'Attributes' is an int stored as a binary! use struct
    attr = shellcon.SFGAO_FOLDER | shellcon.SFGAO_HASSUBFOLDER | \
           shellcon.SFGAO_BROWSABLE
    import struct
    s = struct.pack("i", attr)
    winreg.SetValueEx(key, "Attributes", 0, winreg.REG_BINARY, s)
    # register the context menu handler under the FolderViewSampleType type.
    keypath = "%s\\shellex\\ContextMenuHandlers\\%s" % (ContextMenu._context_menu_type_, ContextMenu._reg_desc_)
    key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, keypath)
    winreg.SetValueEx(key, None, 0, winreg.REG_SZ, ContextMenu._reg_clsid_)
    propsys.PSRegisterPropertySchema(get_schema_fname())
    print(ShellFolder._reg_desc_, "registration complete.")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DllRegisterServer():
    import winreg
    key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT,
                            "Python.File\\shellex")
    subkey = winreg.CreateKey(key, "IconHandler")
    winreg.SetValueEx(subkey, None, 0, winreg.REG_SZ, ShellExtension._reg_clsid_)
    print(ShellExtension._reg_desc_, "registration complete.")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DllRegisterServer():
    import winreg
    key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT,
                            "directory\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    winreg.SetValueEx(key, None, 0, winreg.REG_SZ, ShellExtension._reg_clsid_)
    key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT,
                            "*\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    winreg.SetValueEx(key, None, 0, winreg.REG_SZ, ShellExtension._reg_clsid_)
    print(ShellExtension._reg_desc_, "registration complete.")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DllRegisterServer():
    import winreg
    key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT,
                            "Python.File\\shellex")
    subkey = winreg.CreateKey(key, "ContextMenuHandlers")
    subkey2 = winreg.CreateKey(subkey, "PythonSample")
    winreg.SetValueEx(subkey2, None, 0, winreg.REG_SZ, ShellExtension._reg_clsid_)
    print(ShellExtension._reg_desc_, "registration complete.")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def RegisterAddin(klass):
    import winreg
    key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Excel\\Addins")
    subkey = winreg.CreateKey(key, klass._reg_progid_)
    winreg.SetValueEx(subkey, "CommandLineSafe", 0, winreg.REG_DWORD, 0)
    winreg.SetValueEx(subkey, "LoadBehavior", 0, winreg.REG_DWORD, 3)
    winreg.SetValueEx(subkey, "Description", 0, winreg.REG_SZ, "Excel Addin")
    winreg.SetValueEx(subkey, "FriendlyName", 0, winreg.REG_SZ, "A Simple Excel Addin")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def RegisterAddin(klass):
    import winreg
    key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins")
    subkey = winreg.CreateKey(key, klass._reg_progid_)
    winreg.SetValueEx(subkey, "CommandLineSafe", 0, winreg.REG_DWORD, 0)
    winreg.SetValueEx(subkey, "LoadBehavior", 0, winreg.REG_DWORD, 3)
    winreg.SetValueEx(subkey, "Description", 0, winreg.REG_SZ, klass._reg_progid_)
    winreg.SetValueEx(subkey, "FriendlyName", 0, winreg.REG_SZ, klass._reg_progid_)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DllRegisterServer():
    comclass = IEToolbar

    # register toolbar with IE
    try:
        print("Trying to register Toolbar.\n")
        hkey = winreg.CreateKey( winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Toolbar" )
        subKey = winreg.SetValueEx( hkey, comclass._reg_clsid_, 0, winreg.REG_BINARY, "\0" )
    except WindowsError:
        print("Couldn't set registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ ))
    else:
        print("Set registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ ))
    # TODO: implement reg settings for standard toolbar button

# unregister plugin
项目:SDV-Summary    作者:Sketchy502    | 项目源码 | 文件源码
def add_to_startup(filename='"{}" --silent'.format(sys.argv[0])):
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 0, winreg.KEY_SET_VALUE)
    winreg.SetValueEx(key, REGISTRY_NAME, 0, winreg.REG_SZ, filename)
    key.Close()
项目:keypirinha-plugins    作者:EhsanKia    | 项目源码 | 文件源码
def __setitem__(self,name,value):
        """Item assignment sets key values."""
        self.sam |= KEY_SET_VALUE
        if not isinstance(value,Value):
            value = Value(value,name)
        _winreg.SetValueEx(self.hkey,name,0,value.type,value.data)
项目: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)
项目:GotoX    作者:SeaHOH    | 项目源码 | 文件源码
def refresh_proxy_state(enable=None):
    if enable:
        try:
            ProxyOverride, reg_type = winreg.QueryValueEx(SETTINGS, 'ProxyOverride')
        except:
            ProxyOverride =None
        #??????????
        if not ProxyOverride:
            winreg.SetValueEx(SETTINGS, 'ProxyOverride', 0,  winreg.REG_SZ, ProxyOverride)
    Popen((py_exe, refresh_proxy))
项目:GotoX    作者:SeaHOH    | 项目源码 | 文件源码
def on_disable_proxy(systray):
    proxy_state = proxy_state_menu
    if proxy_state.type & 1:
        winreg.DeleteValue(SETTINGS, 'AutoConfigURL')
    if proxy_state.type & 2:
        winreg.SetValueEx(SETTINGS, 'ProxyEnable', 0,  winreg.REG_DWORD, 0)
    refresh_proxy_state()
项目:GotoX    作者:SeaHOH    | 项目源码 | 文件源码
def disable_x_proxy(type):
    proxy_state = proxy_state_menu
    proxy_state.__delattr__(type)
    #?? AutoConfigURL ??????????
    #??????? Server
    proxy_state.type = 2
    ProxyServer = proxy_state.str
    if ProxyServer == '':
        winreg.SetValueEx(SETTINGS, 'ProxyEnable', 0,  winreg.REG_DWORD, 0)
    else:
        winreg.SetValueEx(SETTINGS, 'ProxyServer', 0,  winreg.REG_SZ, ProxyServer)
    refresh_proxy_state()
项目:GotoX    作者:SeaHOH    | 项目源码 | 文件源码
def enable_proxy(ProxyServer):
    proxy_state = proxy_state_menu
    #?? AutoConfigURL ???? ProxyServer
    if proxy_state.pac:
        winreg.DeleteValue(SETTINGS, 'AutoConfigURL')    
    if not proxy_state.type & 2:
        winreg.SetValueEx(SETTINGS, 'ProxyEnable', 0,  winreg.REG_DWORD, 1)
    proxy_state.type = 2
    proxy_state.http = ProxyServer.http
    proxy_state.https = ProxyServer.https
    winreg.SetValueEx(SETTINGS, 'ProxyServer', 0,  winreg.REG_SZ, proxy_state.str)
    refresh_proxy_state(1)
项目:keyrings.alt    作者:jaraco    | 项目源码 | 文件源码
def set_password(self, service, username, password):
        """Write the password to the registry
        """
        # encrypt the password
        password_encrypted = _win_crypto.encrypt(password.encode('utf-8'))
        # encode with base64
        password_base64 = base64.encodestring(password_encrypted)
        # encode again to unicode
        password_saved = password_base64.decode('ascii')

        # store the password
        key_name = r'Software\%s\Keyring' % service
        hkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER, key_name)
        winreg.SetValueEx(hkey, username, 0, winreg.REG_SZ, password_saved)
项目:BingNiceWallpapers    作者:redstoneleo    | 项目源码 | 文件源码
def add(name, application):
        """add a new autostart entry"""
        key = get_runonce()
        try:
            winreg.SetValueEx(key, name, 0, winreg.REG_SZ, application)
        except WindowsError as e:
            print(e)
        winreg.CloseKey(key)
项目:OnCue    作者:featherbear    | 项目源码 | 文件源码
def load(self, data):
        """
        Prepare the content for display
        """
        self.type = data["type"]
        if self.type == "powerpoint":
            if not self.pptregistry: return False
            # https://mail.python.org/pipermail/python-win32/2012-July/012471.html
            self.PPTapplication = win32com.client.DispatchWithEvents("PowerPoint.Application", self.PPTevents)
            try:
                self.PPTpresentation = self.PPTapplication.Presentations.Open(data["path"].replace("/", "\\"),
                                                                              WithWindow=False)
                # Change PowerPoint output monitor setting (Touch and revert)
                reset = []
                try:
                    reset.append((winreg.QueryValueEx(self.pptregistry, "UseAutoMonSelection")[0],
                                  lambda value: winreg.SetValueEx(self.pptregistry, "UseAutoMonSelection", 0,
                                                                  winreg.REG_DWORD,
                                                                  value)))
                except WindowsError:
                    reset.append((None, lambda _: winreg.DeleteValue(self.pptregistry, "UseAutoMonSelection")))
                try:
                    reset.append((winreg.QueryValueEx(self.pptregistry, "DisplayMonitor")[0],
                                  lambda value: winreg.SetValueEx(self.pptregistry, "DisplayMonitor", 0, winreg.REG_SZ,
                                                                  value)))
                except WindowsError:
                    reset.append((None, lambda _: winreg.DeleteValue(self.pptregistry, "DisplayMonitor")))

                winreg.SetValueEx(self.pptregistry, "DisplayMonitor", 0, winreg.REG_SZ,
                                  self.states["screens"][self.states["display"]["outputID"]]["physical"])

                winreg.SetValueEx(self.pptregistry, "UseAutoMonSelection", 0, winreg.REG_DWORD, 0)

                self.PPTpresentation.SlideShowSettings.ShowPresenterView = False
                self.PPTpresentation.SlideShowSettings.Run()
                self.PPTpresentation.SlideShowWindow.View.AcceleratorsEnabled = False
                self.overlay.setGeometry(self.screen)
                self.overlay.showFullScreen()
                [action(value) for value, action in reset]
            except Exception as e:
                print(e)
        else:
            # Play with VLC
            self.player.set_hwnd(int(self.foreground.winId()))
            self.VLCmedia = self.vlc.media_new(data["path"])
            self.player.set_media(self.VLCmedia)
项目:fontman-desktop-core    作者:fontman    | 项目源码 | 文件源码
def fixed_install_font(src_path):
    # copy the font to the Windows Fonts folder
    dst_path = os.path.join(
        os.environ['SystemRoot'], 'Fonts', os.path.basename(src_path)
    )
    shutil.copy(src_path, dst_path)

    # load the font in the current session
    if not gdi32.AddFontResourceW(dst_path):
        os.remove(dst_path)
        raise WindowsError('AddFontResource failed to load "%s"' % src_path)

    # notify running programs
    user32.SendMessageTimeoutW(
        HWND_BROADCAST, WM_FONTCHANGE, 0, 0, SMTO_ABORTIFHUNG, 1000, None
    )

    # store the fontname/filename in the registry
    filename = os.path.basename(dst_path)
    fontname = os.path.splitext(filename)[0]

    # try to get the font's real name
    cb = wintypes.DWORD()
    if gdi32.GetFontResourceInfoW(
            filename, ctypes.byref(cb), None, GFRI_DESCRIPTION
    ):
        buf = (ctypes.c_wchar * cb.value)()
        if gdi32.GetFontResourceInfoW(
                filename, ctypes.byref(cb), buf, GFRI_DESCRIPTION
        ):
            fontname = buf.value

    is_truetype = wintypes.BOOL()
    cb.value = ctypes.sizeof(is_truetype)
    gdi32.GetFontResourceInfoW(
        filename, ctypes.byref(cb), ctypes.byref(is_truetype), GFRI_ISTRUETYPE
    )

    if is_truetype:
        fontname += ' (TrueType)'

    with winreg.OpenKey(
            winreg.HKEY_LOCAL_MACHINE, FONTS_REG_PATH, 0, winreg.KEY_SET_VALUE
    ) as key:
        winreg.SetValueEx(key, fontname, 0, winreg.REG_SZ, filename)
项目:constructor    作者:conda    | 项目源码 | 文件源码
def remove_from_system_path(pathname, allusers=True, path_env_var='PATH'):
    """Removes all entries from the path which match the value in 'pathname'

       You must call broadcast_environment_settings_change() after you are finished
       manipulating the environment with this and other functions.

       For example,
         # Remove Anaconda from PATH
         remove_from_system_path(r'C:\Anaconda')
         broadcast_environment_settings_change()
    """
    pathname = path.normcase(path.normpath(pathname))

    envkeys = [(reg.HKEY_CURRENT_USER, r'Environment')]
    if allusers:
        envkeys.append((reg.HKEY_LOCAL_MACHINE,
            r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'))
    for root, keyname in envkeys:
        key = reg.OpenKey(root, keyname, 0,
                reg.KEY_QUERY_VALUE|reg.KEY_SET_VALUE)
        reg_value = None
        try:
            reg_value = reg.QueryValueEx(key, path_env_var)
        except WindowsError:
            # This will happen if we're a non-admin install and the user has
            # no PATH variable.
            reg.CloseKey(key)
            continue

        try:
            any_change = False
            results = []
            for v in reg_value[0].split(os.pathsep):
                vexp = sz_expand(v, reg_value[1])
                # Check if the expanded path matches the
                # requested path in a normalized way
                if path.normcase(path.normpath(vexp)) == pathname:
                    any_change = True
                else:
                    # Append the original unexpanded version to the results
                    results.append(v)

            modified_path = os.pathsep.join(results)
            if any_change:
                reg.SetValueEx(key, path_env_var, 0, reg_value[1], modified_path)
        except:
            # If there's an error (e.g. when there is no PATH for the current
            # user), continue on to try the next root/keyname pair
            reg.CloseKey(key)
项目:vivisect-py3    作者:bat-serjo    | 项目源码 | 文件源码
def jit(vdb, line):
    '''
    Enable/Disable the current VDB location as the current Just-In-Time
    debugger for windows applications.

    Usage: jitenable [-D]
    -E  Enable VDB JIT debugging
    -D  Disable JIT debugging
    '''
    argv = e_cli.splitargs(line)
    try:
        opts, args = getopt.getopt(argv, "ED")
    except Exception as e:
        return vdb.do_help('jit')

    try:
        import winreg
    except Exception as e:
        vdb.vprint('Error Importing _winreg: %s' % e)
        return

    HKLM = winreg.HKEY_LOCAL_MACHINE
    HKCU = winreg.HKEY_CURRENT_USER
    REG_SZ = winreg.REG_SZ

    regpath = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug'
    # wow64path = r'SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug'

    # regkey = _winreg.CreateKey(HKLM, regpath)
    regkey = winreg.CreateKey(HKLM, regpath)

    vdb.vprint('JIT Currently: %s' % winreg.QueryValueEx(regkey, 'Debugger')[0])

    setval = None
    for opt, optarg in opts:

        if opt == '-D':
            setval = ''

        elif opt == '-E':
            vdbpath = os.path.abspath(sys.argv[0])
            setval = '%s %s -r -p %%ld -e %%Id' % (sys.executable, vdbpath)
            # _winreg.SetValue(HKLM

    if setval != None:
        vdb.vprint('Setting JIT: %s' % (setval,))
        winreg.SetValueEx(regkey, 'Debugger', None, REG_SZ, setval)