我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用winreg.REG_DWORD。
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
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
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")
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_)
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)
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()
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()
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)
def _win32_is_nic_enabled(self, lm, guid, interface_key): # Look in the Windows Registry to determine whether the network # interface corresponding to the given guid is enabled. # # (Code contributed by Paul Marks, thanks!) # try: # This hard-coded location seems to be consistent, at least # from Windows 2000 through Vista. connection_key = _winreg.OpenKey( lm, r'SYSTEM\CurrentControlSet\Control\Network' r'\{4D36E972-E325-11CE-BFC1-08002BE10318}' r'\%s\Connection' % guid) try: # The PnpInstanceID points to a key inside Enum (pnp_id, ttype) = _winreg.QueryValueEx( connection_key, 'PnpInstanceID') if ttype != _winreg.REG_SZ: raise ValueError device_key = _winreg.OpenKey( lm, r'SYSTEM\CurrentControlSet\Enum\%s' % pnp_id) try: # Get ConfigFlags for this device (flags, ttype) = _winreg.QueryValueEx( device_key, 'ConfigFlags') if ttype != _winreg.REG_DWORD: raise ValueError # Based on experimentation, bit 0x1 indicates that the # device is disabled. return not (flags & 0x1) finally: device_key.Close() finally: connection_key.Close() except (EnvironmentError, ValueError): # Pre-vista, enabled interfaces seem to have a non-empty # NTEContextList; this was how dnspython detected enabled # nics before the code above was contributed. We've retained # the old method since we don't know if the code above works # on Windows 95/98/ME. try: (nte, ttype) = _winreg.QueryValueEx(interface_key, 'NTEContextList') return nte is not None except WindowsError: return False
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)
def _win32_is_nic_enabled(self, lm, guid, interface_key): # Look in the Windows Registry to determine whether the network # interface corresponding to the given guid is enabled. # # (Code contributed by Paul Marks, thanks!) # try: # This hard-coded location seems to be consistent, at least # from Windows 2000 through Vista. connection_key = _winreg.OpenKey( lm, r'SYSTEM\CurrentControlSet\Control\Network' r'\{4D36E972-E325-11CE-BFC1-08002BE10318}' r'\%s\Connection' % guid) try: # The PnpInstanceID points to a key inside Enum (pnp_id, ttype) = _winreg.QueryValueEx( connection_key, 'PnpInstanceID') if ttype != _winreg.REG_SZ: raise ValueError device_key = _winreg.OpenKey( lm, r'SYSTEM\CurrentControlSet\Enum\%s' % pnp_id) try: # Get ConfigFlags for this device (flags, ttype) = _winreg.QueryValueEx( device_key, 'ConfigFlags') if ttype != _winreg.REG_DWORD: raise ValueError # Based on experimentation, bit 0x1 indicates that the # device is disabled. return not flags & 0x1 finally: device_key.Close() finally: connection_key.Close() except (EnvironmentError, ValueError): # Pre-vista, enabled interfaces seem to have a non-empty # NTEContextList; this was how dnspython detected enabled # nics before the code above was contributed. We've retained # the old method since we don't know if the code above works # on Windows 95/98/ME. try: (nte, ttype) = _winreg.QueryValueEx(interface_key, 'NTEContextList') return nte is not None except WindowsError: # pylint: disable=undefined-variable return False