나는 Activestate.org에서 다음과 같은 파이썬 제조법을 취한 다음 간단히 키 삭제 방법을 추가했지만 오류 5, 액세스가 거부되고 키가 가짜 키입니다. 방금이 기능을 사용해 보았습니다. 코드는 다음과 같습니다.파이썬 RegDeleteKey 오류 5 액세스가 거부되었습니다
## {{{ http://code.activestate.com/recipes/576860/ (r2)
import win32api
import win32con
def regquerysubkeys(handle, key, keylist=[]):
#get registry handle
reghandle = win32api.RegOpenKeyEx(handle, key, 0, win32con.KEY_ALL_ACCESS)
try:
i = 0
#enumerates subkeys and recursively calls this function again
while True:
subkey = win32api.RegEnumKey(reghandle, i)
#the following is the line I added myself
win32api.RegDeleteKey(handle, key)
i += 1
#braintwister here ;-)
regquerysubkeys(handle, key + subkey + "\\", keylist)
except win32api.error as ex:
#If no more subkeys can be found, we can append ourself
if ex[0] == 259:
keylist.append(key)
#unexpected exception is raised
else:
raise
finally:
#do some cleanup and close the handle
win32api.RegCloseKey(reghandle)
#returns the generated list
print keylist
#call to the function
regquerysubkeys(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\\suga\\")
이들은 콘솔에 들어가는 오류입니다.
Traceback (most recent call last):
File "C:\EclipseWorkspaces\csse120\MMS-auto\test1.py", line 34, in <module>
regquerysubkeys(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\\suga\\")
File "C:\EclipseWorkspaces\csse120\MMS-auto\test1.py", line 14, in regquerysubkeys
win32api.RegDeleteKey(handle, key)
pywintypes.error: (5, 'RegDeleteKey', 'Access is denied.')
아무도 도와 줄 수 있습니까?
필자는 설명서에서이 글을 읽었지 만, 32bit를 사용하고 있기 때문에 이런 종류의 문제는 없어야합니다. – nassio
이상하지만 바이러스 백신 소프트웨어를 끄면 내 문제가 해결됩니다. –