I'm trying to execute a command in a remote desktop cmd. I have the IP, username and password of that remote desktop and I can access it through the remote desktop application. I have tried this code to send the 'uxm getrole' command to the remote cmd but I can't get the output of the cmd. I'm converting this python file into executable with pyinstaller because the computer that runs this code can't have python installed, I don't know if could be an issue with that.
import wmi
from socket import *
ip = ip_address
username = 'username'
password = 'password'
try:
print("Establishing connection to %s" %ip)
connection = wmi.WMI(ip, user=username, password=password)
print("Connection established")
res = connection.Win32_Process.Create(CommandLine='cmd.exe /c uxm getrole')
print(res)
except wmi.x_wmi:
print("Your Username and Password of " getfqdn(ip) " are wrong.")
except Exception as e:
print(e)
Is there a way to receive the output from the remote cmd without having to create a SSH in the remote desktop? Maybe I should use subprocess library when I open the connection? But I don't know how to do it.
Thank you.
CodePudding user response:
If you are not sticking with python. You can use PsExec
to execute remote commands.
https://docs.microsoft.com/en-us/sysinternals/downloads/psexec