On Fri, Aug 21, 2009 at 9:33 AM, Jamie <jamie.iva...@gmail.com> wrote:
> My goal is to remotely remove the registry keys for McAfee. I don't > know how winreg handles an exception if a key doesn't exist, but I > setup my script to skip the exception. But it doesn't seem to work > right.. I think the script should be self explanitory, please help! > Please forgive me, but I'm a python newbie. > > ## SCRIPT ## > > import _winreg > > print "Removing McAfee registry entries" > hkey = _winreg.ConnectRegistry(r'\ > \000000439140PC',_winreg.HKEY_LOCAL_MACHINE) > try: > _winreg.DeleteKey('SYSTEM\CurrentControlSet\Enum\Root','LEGACY_MFEAPFK') > except: > pass > You have to "open" the key first-- the first argument to .DeleteKey is not a string. E.g., do: key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Enum\Root') _winreg.DeleteKey(key, 'LEGACY_MFEAPFK' _winreg.CloseKey(key) 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. HTH, --S
-- http://mail.python.org/mailman/listinfo/python-list