RegUnloadkey access denied

future_retro at yahoo.co.uk future_retro at yahoo.co.uk
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 |
ntsecuritycon.TOKEN_QUERY
htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(),
flags)
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 =
win32api.RegOpenKeyEx(key,'Marc\\test',0,win32con.KEY_ALL_ACCESS)
win32api.RegSetValueEx(okey,'test',0,_winreg.REG_DWORD,0)
#win32api.RegSaveKey(okey,'c:\\ntuser2.dat',None)
#win32api.RegFlushKey(_winreg.HKEY_USERS)
win32api.RegUnLoadKey(key,'Marc')




More information about the Python-list mailing list