问题
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