RegUnloadkey access denied

future_retro at future_retro at
Fri Jul 22 11:01:28 CEST 2005

In the following script I can't get the reg key to unload.  Anyone got
any ideas?  I can load and save the key without any problems.  I can
unload the key from regedit and have checked security on the key.  The
docs don't mention any special privileges are needed
(SeRestorePrivilege should do it).  I'm stumped.  Cheers peeps, MW.

import ntsecuritycon
import win32security
import win32api
import _winreg
import win32con

flags = ntsecuritycon.TOKEN_ADJUST_PRIVILEGES |
htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(),
Loadid = win32security.LookupPrivilegeValue(None, 'SeRestorePrivilege')
#Saveid = win32security.LookupPrivilegeValue(None, 'SeBackupPrivilege')
LoadPrivilege = [(Loadid, ntsecuritycon.SE_PRIVILEGE_ENABLED)]
#SavePrivilege = [(Saveid, ntsecuritycon.SE_PRIVILEGE_ENABLED)]
win32security.AdjustTokenPrivileges(htoken, 0, LoadPrivilege)
#win32security.AdjustTokenPrivileges(htoken, 0, SavePrivilege)

key = _winreg.HKEY_USERS
hkey = win32api.RegLoadKey(key,'Marc','c:\\ntuser.dat')
okey =

More information about the Python-list mailing list