2012-04-10 2 views
0

나는 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.') 

아무도 도와 줄 수 있습니까?

답변

0

언제든지 64 비트 Windows 7을 실행하고 있습니까? 삭제를 위해 다른 API를 사용해야하는 32 비트 및 64 비트 프로그램을 모두 실행하는 계정에 대한 레지스트리 구조의 일부 변경 사항이있었습니다. The RegDeleteKey Win32 API documentationRegDeleteKeyEx을 사용하는 경우가 있습니다. Win32 API는 한 주요 버전의 Windows에서 다음 버전으로 안정적으로 사용하기가 어렵습니다. 불행히도 pywin32은 여러 가지 두통을 숨기기 위해 최선을 다하고 있지만 효과적으로 사용하려면 먼저 Win32 API와주의 사항을 알고 있어야합니다.

+0

필자는 설명서에서이 글을 읽었지 만, 32bit를 사용하고 있기 때문에 이런 종류의 문제는 없어야합니다. – nassio

+0

이상하지만 바이러스 백신 소프트웨어를 끄면 내 문제가 해결됩니다. –

관련 문제