Problem with winreg - The object is not a PyHKEY object

Jamie jamie.ivanov at gmail.com
Fri Aug 21 18:33:57 CEST 2009


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

#try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEAVFK')
#except:
# pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEBOPK')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEHIDK')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEHIDK01')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFERKDK')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFETDIK')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_NAIAVFILTER1')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_NAIAVFILTER101')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MCSHIELD')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','MCTASKMANAGER')
except:
pass

try:
_winreg.DeleteKey('\SOFTWARE','McAfee')
except:
pass

try:
_winreg.DeleteKey('\SOFTWARE','Network Associates')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','AlertManager')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet
\Services','McAfeeFramework')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','McShield')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet
\Services','McTaskManager')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfeapfk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfeavfk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfebopk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfehidk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfehidk01')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mferkdk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfetdik')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','NaiAvFilter1')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet
\Services','NaiAvFilter101')
except:
pass

## END SCRIPT ##

## OUTPUT ##
Removing McAfee registry entries
Traceback (most recent call last):
File "uninstallMcafee.py", line 11, in <module>
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEAVFK')
TypeError: The object is not a PyHKEY object
## END OUTPUT ##



More information about the Python-list mailing list