Skip to content

Instantly share code, notes, and snippets.

@kadirmalak
kadirmalak / rdp-disconnect.py
Last active August 31, 2017 12:17
Remotely logoff / disconnect / reset multiple RDP sessions
# USAGE: python rdp-disconnect.py -u kadir.malak -s 192.168.0.10 192.168.0.11 somehostname1 somehostname2
from subprocess import check_output, STDOUT
import argparse
def rdp_session_id(server, username):
output = check_output('qwinsta /server:%s %s' % (server, username), stderr=STDOUT).decode('latin1')
if 'No session exists' in output:
return -1
lines = [line.split() for line in output.split('\r\n')]