<br><br><div class="gmail_quote">On Fri, Aug 21, 2009 at 9:33 AM, Jamie <span dir="ltr"><<a href="mailto:jamie.ivanov@gmail.com">jamie.ivanov@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
My goal is to remotely remove the registry keys for McAfee. I don't<br>
know how winreg handles an exception if a key doesn't exist, but I<br>
setup my script to skip the exception. But it doesn't seem to work<br>
right.. I think the script should be self explanitory, please help!<br>
Please forgive me, but I'm a python newbie.<br>
<br>
## SCRIPT ##<br>
<br>
import _winreg<br>
<br>
print "Removing McAfee registry entries"<br>
hkey = _winreg.ConnectRegistry(r'\<br>
\000000439140PC',_winreg.HKEY_LOCAL_MACHINE)<br>
try:<br>
_winreg.DeleteKey('SYSTEM\CurrentControlSet\Enum\Root','LEGACY_MFEAPFK')<br>
except:<br>
pass<br>
</blockquote><div><br></div><div>You have to "open" the key first-- the first argument to .DeleteKey is not a string.</div><div><br></div><div>E.g., do:</div><div><br></div><div>key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Enum\Root')</div>
<div>_winreg.DeleteKey(key, 'LEGACY_MFEAPFK'</div><div>_winreg.CloseKey(key)</div><div><br></div><div>The above is an example off the top of my head, not actually tested-- But that's sorta your problem, I believe: .DeleteKey operates on a key /handle/ in its first argument, not a string. The second argument is a string.</div>
<div><br></div><div>HTH,</div><div><br></div><div>--S</div></div>