1

I want to automate closing the remote desktop application using python. I open the remote desktop using mstsc. When I do

os.system("TASKKILL /F /IM mstsc.exe")

It is killing all the remote desktop applications that are open. Is there a way I can specify through python which remote desktop it has to close. I have 2 or more instances of remote desktop open and I require my program to close only specific connection. Is there a way I can pass the IP address or process ID or something.

user2927392
  • 249
  • 3
  • 11
  • You can only disconnect rdp session from local. If you would like to close session you need to do that from remote machine. To achieve what you said you need to write a server application on the remote machine which listens a port to capture your commands to close rdp session. – scriptmonster Nov 08 '13 at 08:50

1 Answers1

0

To close one of the mstsc, you should know the pid of it. If you are opening mstsc.exe from a python script itself, then you could capture the pid of that instance.

p = Popen('C:\Windows\System32\mstsc.exe "connection.rdp"') print p.pid

Then kill the exe using pid.

Mohan
  • 1