def getCurrentActiveDesktopName(self, sessionId=None): if not RUNNING_ON_WINDOWS: return None if not ('opsiclientd_rpc' in config.getDict() and 'command' in config.getDict()['opsiclientd_rpc']): raise Exception("opsiclientd_rpc command not defined") if sessionId is None: sessionId = System.getActiveSessionId() if sessionId is None: sessionId = System.getActiveConsoleSessionId() rpc = f"setCurrentActiveDesktopName(\"{sessionId}\", System.getActiveDesktopName())" cmd = config.get('opsiclientd_rpc', 'command') + ' "' + rpc.replace( '"', '\\"') + '"' try: System.runCommandInSession(command=cmd, sessionId=sessionId, desktop="winlogon", waitForProcessEnding=True, timeoutSeconds=60, noWindow=True) except Exception as err: # pylint: disable=broad-except logger.error(err) desktop = self._currentActiveDesktopName.get(sessionId) if not desktop: logger.warning( "Failed to get current active desktop name for session %s, using 'default'", sessionId) desktop = "default" self._currentActiveDesktopName[sessionId] = desktop logger.debug( "Returning current active dektop name '%s' for session %s", desktop, sessionId) return desktop
def switchDesktop(self, desktop, sessionId=None): # pylint: disable=no-self-use if not ('opsiclientd_rpc' in config.getDict() and 'command' in config.getDict()['opsiclientd_rpc']): raise Exception("opsiclientd_rpc command not defined") desktop = forceUnicode(desktop) if sessionId is None: sessionId = System.getActiveSessionId() if sessionId is None: sessionId = System.getActiveConsoleSessionId() sessionId = forceInt(sessionId) rpc = f"noop(System.switchDesktop('{desktop}'))" cmd = f'{config.get("opsiclientd_rpc", "command")} "{rpc}"' try: System.runCommandInSession(command=cmd, sessionId=sessionId, desktop=desktop, waitForProcessEnding=True, timeoutSeconds=60, noWindow=True) except Exception as err: # pylint: disable=broad-except logger.error(err)