def onRunCOMRegistrationFixesCommand(self, evt): if isInMessageBox: return if gui.messageBox( # Translators: A message to warn the user when starting the COM Registration Fixing tool _("You are about to run the COM Registration Fixing tool. This tool will try to fix common system problems that stop NVDA from being able to access content in many programs including Firefox and Internet Explorer. This tool must make changes to the System registry and therefore requires administrative access. Are you sure you wish to proceed?"), # Translators: The title of the warning dialog displayed when launching the COM Registration Fixing tool _("Warning"),wx.YES|wx.NO|wx.ICON_WARNING,self )==wx.NO: return progressDialog = IndeterminateProgressDialog(mainFrame, # Translators: The title of the dialog presented while NVDA is running the COM Registration fixing tool _("COM Registration Fixing Tool"), # Translators: The message displayed while NVDA is running the COM Registration fixing tool _("Please wait while NVDA tries to fix your system's COM registrations.") ) try: import systemUtils systemUtils.execElevated(config.SLAVE_FILENAME, ["fixCOMRegistrations"]) except: log.error("Could not execute fixCOMRegistrations command",exc_info=True) progressDialog.done() del progressDialog # Translators: The message displayed when the COM Registration Fixing tool completes. gui.messageBox(_("COM Registration Fixing tool complete"), # Translators: The title of a dialog presented when the COM Registration Fixing tool is complete. _("COM Registration Fixing Tool"), wx.OK)
def setSystemConfigToCurrentConfig(): fromPath = globalVars.appArgs.configPath if ctypes.windll.shell32.IsUserAnAdmin(): _setSystemConfig(fromPath) else: import systemUtils res = systemUtils.execElevated(SLAVE_FILENAME, ("setNvdaSystemConfig", fromPath), wait=True) if res==2: import installer raise installer.RetriableFailure elif res!=0: raise RuntimeError("Slave failure")
def setStartOnLogonScreen(enable): if getStartOnLogonScreen() == enable: return try: # Try setting it directly. _setStartOnLogonScreen(enable) except WindowsError: # We probably don't have admin privs, so we need to elevate to do this using the slave. import systemUtils if systemUtils.execElevated( SLAVE_FILENAME, ("config_setStartOnLogonScreen", "%d" % enable), wait=True) != 0: raise RuntimeError("Slave failed to set startOnLogonScreen")
def setStartOnLogonScreen(enable: bool) -> None: """ Not to be confused with setStartAfterLogon. Toggle whether NVDA starts on the logon screen automatically. On failure to set, retries with escalated permissions. Raises a RuntimeError on failure. """ if getStartOnLogonScreen() == enable: return try: # Try setting it directly. _setStartOnLogonScreen(enable) except WindowsError: log.debugWarning("Failed to set start on logon screen's config.") # We probably don't have admin privs, so we need to elevate to do this using the slave. import systemUtils if systemUtils.execElevated( SLAVE_FILENAME, ("config_setStartOnLogonScreen", "%d" % enable), wait=True ) != 0: raise RuntimeError("Slave failed to set startOnLogonScreen")
def execElevated(*args, **kwargs): import systemUtils systemUtils.execElevated(*args, **kwargs)
def doInstall(createDesktopShortcut=True, startOnLogon=True, isUpdate=False, copyPortableConfig=False, silent=False, startAfterInstall=True): progressDialog = gui.IndeterminateProgressDialog( gui.mainFrame, # Translators: The title of the dialog presented while NVDA is being updated. _("Updating NVDA") if isUpdate # Translators: The title of the dialog presented while NVDA is being installed. else _("Installing NVDA"), # Translators: The message displayed while NVDA is being updated. _("Please wait while your previous installation of NVDA is being updated." ) if isUpdate # Translators: The message displayed while NVDA is being installed. else _("Please wait while NVDA is being installed")) try: res = systemUtils.execElevated(config.SLAVE_FILENAME, [ "install", str(int(createDesktopShortcut)), str(int(startOnLogon)) ], wait=True, handleAlreadyElevated=True) if res == 2: raise installer.RetriableFailure if copyPortableConfig: installedUserConfigPath = config.getInstalledUserConfigPath() if installedUserConfigPath: gui.ExecAndPump(installer.copyUserConfig, installedUserConfigPath) except Exception as e: res = e log.error("Failed to execute installer", exc_info=True) progressDialog.done() del progressDialog if isinstance(res, installer.RetriableFailure): # Translators: a message dialog asking to retry or cancel when NVDA install fails message = _( "The installation is unable to remove or overwrite a file. Another copy of NVDA may be running on another logged-on user account. Please make sure all installed copies of NVDA are shut down and try the installation again." ) # Translators: the title of a retry cancel dialog when NVDA installation fails title = _("File in Use") if winUser.MessageBox(None, message, title, winUser.MB_RETRYCANCEL) == winUser.IDRETRY: return doInstall(createDesktopShortcut=createDesktopShortcut, startOnLogon=startOnLogon, copyPortableConfig=copyPortableConfig, isUpdate=isUpdate, silent=silent, startAfterInstall=startAfterInstall) if res != 0: log.error("Installation failed: %s" % res) # Translators: The message displayed when an error occurs during installation of NVDA. gui.messageBox( _("The installation of NVDA failed. Please check the Log Viewer for more information." ), # Translators: The title of a dialog presented when an error occurs. _("Error"), wx.OK | wx.ICON_ERROR) return if not silent: msg = ( # Translators: The message displayed when NVDA has been successfully installed. _("Successfully installed NVDA. ") if not isUpdate # Translators: The message displayed when NVDA has been successfully updated. else _("Successfully updated your installation of NVDA. ")) # Translators: The message displayed to the user after NVDA is installed # and the installed copy is about to be started. gui.messageBox( msg + _("Please press OK to start the installed copy."), # Translators: The title of a dialog presented to indicate a successful operation. _("Success")) if startAfterInstall: # #4475: ensure that the first window of the new process is not hidden by providing SW_SHOWNORMAL shellapi.ShellExecute( None, None, os.path.join(installer.defaultInstallPath, 'nvda.exe'), None, None, winUser.SW_SHOWNORMAL) else: gui.safeAppExit()