RegUnloadkey access denied

future_retro at yahoo.co.uk future_retro at yahoo.co.uk
Fri Jul 22 07:04:34 EDT 2005


solved it!

I need to close the key first

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_SET_VALUE)
win32api.RegSetValueEx(okey,'test',0,_winreg.REG_DWORD,0)
win32api.RegCloseKey(okey)
win32api.RegUnLoadKey(key,'Marc')




More information about the Python-list mailing list