(self, params, **kwargs)
| 508 | return rdp_parser |
| 509 | |
| 510 | def execute(self, params, **kwargs): |
| 511 | record_name = kwargs.pop('record', None) |
| 512 | if not record_name: |
| 513 | ls = RecordListCommand() |
| 514 | return ls.execute(params, record_type=['serverCredentials'], verbose=True, **kwargs) |
| 515 | |
| 516 | record = find_record(params, record_name, types=['serverCredentials']) |
| 517 | |
| 518 | login = BaseConnectCommand.get_record_field(record, 'login') |
| 519 | if not login: |
| 520 | logging.warning('Record "%s" does not have user name.', record.title) |
| 521 | return |
| 522 | |
| 523 | host = BaseConnectCommand.get_record_field(record, 'host') |
| 524 | if not host: |
| 525 | logging.warning('Record "%s" does not have host.', record.title) |
| 526 | return |
| 527 | host_name, _, port = host.partition(':') |
| 528 | |
| 529 | password = BaseConnectCommand.get_record_field(record, 'password') |
| 530 | if password: |
| 531 | command = ['cmdkey', f'/generic:{host_name}', f'/user:{login}', f'/pass:{password}'] |
| 532 | subprocess.run(command, stdout=subprocess.DEVNULL) |
| 533 | # os.system(f'cmdkey /generic:{host_name} /user:{login} /pass:{password} > NUL') |
| 534 | |
| 535 | def clear_password(): |
| 536 | subprocess.run(['cmdkey', f'/delete:{host_name}'], stdout=subprocess.DEVNULL) |
| 537 | # os.system(f'cmdkey /delete:{host_name} > NUL') |
| 538 | self.run_at_the_end.append(clear_password) |
| 539 | |
| 540 | options = f'/v:{host_name}' |
| 541 | if port: |
| 542 | options += ':' + port |
| 543 | command = ['mstsc', options] |
| 544 | self.command = shlex.join(command) |
| 545 | |
| 546 | logging.info('Connecting to "%s" ...', record.title) |
| 547 | self.execute_shell(record=record, stage='rdp') |
| 548 | |
| 549 | |
| 550 | connect_command_description = ''' |
nothing calls this directly
no test coverage detected