I am writing a Python script to retrieve the list of administrators users from a remote Windows box using the WMI client (https://pypi.python.org/pypi/WMI/1.4.9). This is the code I am using:
import wmi
wql = r'SELECT * FROM Win32_GroupUser WHERE GroupComponent="Win32_Group.Domain=\"MY_MACHINE\",Name=\"Administrators\""'
host = '10.253.6.38'
domain = 'My_Domain'
user = 'My_User'
auth_user = '{0}\{1}'.format(domain, user)
password = 'Secret
wmic = wmi.WMI(host, user=auth_user, password=password)
admins_list = wmic.query(wql)
But when I try running the query I get an exception with this error:
com_error: (-2147217385, 'OLE error 0x80041017', None, None)
I cannot find anywhere what that error means. If I run the exact same script but I use another query like for example SELECT PartComponent FROM Win32_SystemUsers
, it works fine. To make it more strange, if I run the same query that is giving me problems directly in the remote machine using the "WMI Tester" it works perfectly. I have spent more than 2 days trying to make this work with no luck, I've run out of ideas. If anyone knows what is going on I could use some help here. thanks.
User contributions licensed under CC BY-SA 3.0