[python-win32] Accessing a Remote Registry....
tom.moulton at cox.net
tom.moulton at cox.net
Tue Apr 15 19:07:46 CEST 2008
I have found many references to accessing a registry remotely; however, none
that work for me. Admittedly, I am a bit green on understanding Windows
security permissions and the like. I have tried a number of solutions (i.e.,
wmi, win32api, _winreg), but to no avail. I am trying to update registry
settings between Windows XP systems using user a local administrator account for
authentication. I've tried the following...
BEGIN SNIPPET 1:
c = wmi.WMI(computer='<ip_address>', user='<username>',
password='<password>')
reg = c.Registry()[0]
reg.EnumKey (hDefKey=_winreg.HKEY_LOCAL_MACHINE, sSubKeyName="Software")
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\wmi.py", line 491, in __getattr__
return getattr (self.ole_object, attribute)
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 496, in
__getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: <unknown>.EnumKey
END SNIPPET 1
BEGIN SNIPPET 2:
objSWbemLocator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices =
objSWbemLocator.ConnectServer('<ip_address>','root\default:Cimv2', '<username>',
'<password>')
objReg = objSWbemServices.Get('StdRegProv')
objReg.EnumKey(hDefKey=_winreg.HKEY_LOCAL_MACHINE, sSubKeyName='Software')
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 491, in
__getattr__
raise pythoncom.com_error, details
com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemObjectEx', 'Invalid
parameter ', None, 0, -2147217400), None)
END SNIPPET 2
I've looked at using the wmi.Registry function; however, it only allows you to
specify the computer name and not any credentials (i.e., username and password).
I've also tried a various forms of monikers (e.g., //<ip_address>/root/default);
however, anytime I specify the IP address within the moniker I get an Access
Denied error (see below). Also, passing in the moniker seems to override use of
the user, password and computer arguments.
BEGIN SNIPPET 3:
reg = wmi.WMI(computer='<ip_address>,
moniker='winmgmts://<ip_address>/root/default:StdRegProv', user='<username>',
password='<password>')
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\wmi.py", line 1190, in connect
handle_com_error (error_info)
File "C:\Python25\lib\site-packages\wmi.py", line 189, in handle_com_error
raise x_wmi, "\n".join (exception_string)
x_wmi: -0x7ff8fffb - Access is denied.
END SNIPPET 3
Thanks,
Tom
More information about the python-win32
mailing list