#!/usr/bin/env python import sys, codecs, os, chardet if len(sys.argv) != 2: print " Usage:" print " ",sys.argv[0],"file.rdp" print sys.exit(1) command = "rdesktop" seamlessrdp = "seamlessrdpshell.exe" server = None heigth = None width = None options = "" seamless = False keymap = "es" alternateshell = None defaultPassword = "kiosko00." setPassword = True charset = chardet.detect(open(sys.argv[1], "r").read()) for line in codecs.open(sys.argv[1], "r", charset["encoding"]).readlines(): tokens = line.rstrip("\n\r").split(":", 2) if tokens[0] == "screen mode id" and tokens[2] == "2": options = options + " -f" elif tokens[0] == "full address": server = tokens[2] elif tokens[0] == "desktopwidth": width = tokens[2] elif tokens[0] == "desktopheight": height = tokens[2] elif tokens[0] == "session bpp": options = options + " -a " + tokens[2] elif tokens[0] == "audiomode": if tokens[2] == "0": options = options + " -r sound:local" elif tokens[2] == "1": options = options + " -r sound:remote" elif tokens[2] == "2": options = options + " -r sound:off" elif tokens[0] == "remoteapplicationmode" and tokens[2] == "1": options = options + " -A" seamless = True elif tokens[0] == "alternate shell": alternateshell = tokens[2] elif tokens[0] == "username": options = options + " -u \"" + tokens[2] + "\"" elif tokens[0] == "password": options = options + " -p " + tokens[2] setPassword = False # more options options = options + " -k " + keymap if width != None and height != None: options = options + " -g " + width + "x" + height if setPassword: options = options + " -p \"" + defaultPassword +"\"" if alternateshell != None and not seamless: options = options + " -s " + alternateshell elif alternateshell != None and seamless: options = options + " -s \"" + seamlessrdp + " " + alternateshell + "\"" # command command = command + options + " " + server print(command) os.system(command)