how to close remote desktop window using python

☆樱花仙子☆ 提交于 2019-12-11 05:17:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/19854866/how-to-close-remote-desktop-window-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!