[Tutor] _winreg problems enumerating
Kent Johnson
kent37 at tds.net
Thu Apr 14 12:23:36 CEST 2005
Gallagher Timothy-TIMOTHYG wrote:
> am new to python and want to learn this language. I am having troubles
> finding examples and tutorials for use on windows boxes. I do most of my
> stuff in perl and php but want better socket support, so I am giving python
> a try. I am writing a script to connect to remote registry's because of
> this new IM virus. I can create reg entries and delete them but I cannot
> enumerate them, here is my code.
>
> import _winreg
>
> host = "127.0.0.1" # local host
> key = _winreg.ConnectRegistry(host, _winreg.HKEY_LOCAL_MACHINE)
> E_key = _winreg.EnumValue(key,
> r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
_winreg is pretty low level. It can only access one level down from the current key. Here is a
program that navigates a path in the registry one step at a time:
import _winreg
def openKey(key, path):
pathElements = path.split('\\')
for elem in pathElements:
key = _winreg.OpenKey(key, elem)
return key
key = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
runKey = openKey(key, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
print _winreg.QueryInfoKey(runKey)
Kent
More information about the Tutor
mailing list