user3148235
user3148235

Reputation: 21

python connect to windows machine and execute commands remotely

i was trying to remote from a windows machine (this machine has python26 installed) to another windows machine (this machine doesnt has python installed) using python script. i googled through and found out that WMI module is very good. so i tried using this. below is my code :

    class WindowsMachine:
        def __init__(self, ip, username, password, remote_path=REMOTE_PATH):
            self.ip = ip
            self.username = username
            self.password = password
            self.remote_path = remote_path
            try:
                print "Establishing connection to %s" %self.ip
                self.connection = wmi.WMI(self.ip, user=self.username, password=self.password)
                print "Connection established"
            except wmi.x_wmi:
                print "Could not connect to machine"
                raise

but im getting error message : wmi.x_access_denied". i have googled up for a solution for this but didnt get a proper answer. can someone please help? anyone encountered this before?

Upvotes: 0

Views: 7116

Answers (1)

R Hyde
R Hyde

Reputation: 10409

This issue is usually permission related. There is a good article on troubleshooting WMI here. In addition to that, I recommend using wmic (the WMI command line client) to isolate the problem before going back to the Python code.

Here is an example of wmic failing due to the user not being authenticated:

C:> wmic /node:10.0.0.1 os get caption
Node - 10.0.0.1
ERROR:
Code = 0x80070005
Description = Access is denied.
Facility = Win32

Here is the same command, but this time it succeeds because the user is authenticated:

C:> wmic /node:10.0.0.1 /user:example\user /password:123456 os get caption
Caption
Microsoft(R) Windows(R) Server 2003, Standard Edition

Upvotes: 1

Related Questions