3

I am trying to create a directory on a remote computer using wmi and python. I am able to successfully run any batch file by providing the complete path to it. But not execute system command.

This following code does not create a directory on the remote computer.

conn = wmi.WMI('172.20.23.45', user='Administrator', password='Pass@123')
conn.Win32_Process.Create(CommandLine='mkdir temp')

1 Answer 1

1

It could be done as.

conn.Win32_Process.Create(CommandLine='cmd.exe /c mkdir temp')
Sign up to request clarification or add additional context in comments.

4 Comments

what does /c do? Thanks.
/C - Carries out the command specified by string and then terminates. For more info "cmd.exe /?"
@Rahul You can redirect to a file and then read from that. ex: ls > output.txt
@reply Redirect it to a file and then read from it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.