Scanning through Windows registry...
Unknown Hero
unknown_hero007 at hotmail.com
Fri May 9 07:33:36 EDT 2008
On 9 touko, 12:51, Unknown Hero <unknown_hero... at hotmail.com> wrote:
> Finally managed to get it to work (heh, I was pretty darn lost even
> though I had the best help) but as promised, I'll post my code here
> for those who might be interested in it. The biggest of thanks to Tim
> Golden, who basically walked me step-by-step through this. Most of the
> code is copied from his examples above.
>
> [large piece of code here]
>
> Not the most effecient code, I'm sure, but it does what I want it to
> do :D
>
> Thank you once more, Tim. Also, thank you, Mike, for your advice on
> saving the registry. I would have forgotten to note backing up the
> registry in the beginning if it wasn't for you bringing that up. :D
Hmm... Improving your code is always fun :D but quick fixes to make it
replace search results that contain something more than 'old' here
don't
seem to work.
So I made it command-line, with arguments Hive, old, new.
If I ran the script as registry.py HKEY_LOCAL_MACHINE something
"something else"
and I had made dummy values to the registry like "there is something
here" it
won't update to "there is something else here".
I tried this, can Tim (or someone else) possibly help?
if type == _winreg.REG_SZ:
Character = 0
Correct = 0
FoundStart = FoundEnd = 0
Found = False
for y in range(len(data)):
if Character < len(old):
if old[Character] is data[y]:
Character = Character + 1
Correct = Correct + 1
if Correct is len(old):
Found = True
Replace = ""
Character = 0
for y in range(len(data)):
if old[0] is data[y]:
FoundStart = int(y)
FoundEnd = FoundStart + oldLength
for y in range(FoundStart):
Replace = Replace + data[y]
for y in range(len(new)):
Replace = Replace + new[y]
for y in range(FoundEnd, len(data)):
Replace = Replace + data[y]
if Found:
_winreg.SetValueEx (key.key, name, 0, type, data.replace
(old, Replace))
Thanks in advance.
More information about the Python-list
mailing list