Problem with winreg - The object is not a PyHKEY object

J

Jamie

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 ##
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top