[python-win32] Accessing a Remote Registry....

kirancnair kiran.nair at rsa.com
Thu Sep 22 13:54:49 CEST 2011


You can do something like this:

<code>
import _winreg
import wmi
c = wmi.WMI(computer="XXX.XXX.XXX.XXX", user="devuser",
password="devpass1!",namespace="root/default").StdRegProv


result, names = c.EnumKey (
  hDefKey=_winreg.HKEY_LOCAL_MACHINE,
  sSubKeyName="SYSTEM\ControlSet001\Services\MRxDAV"
)

for item in names:
    print item
</code>


Tom Moulton-2 wrote:
> 
> 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 
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
> 
> 

-- 
View this message in context: http://old.nabble.com/Accessing-a-Remote-Registry....-tp16706968p32503805.html
Sent from the Python - python-win32 mailing list archive at Nabble.com.



More information about the python-win32 mailing list