views:

148

answers:

1

I am trying to migrate microsoft office settings from one system to other system by backing up office registry and restoring it on the destination machine using Python.I am able to do the saving part,but on trying to restore the existing settings in destination machine to overwrite existing office settings,i am getting an error. This is the code for restoring :-

import os, sys
import _winreg
import win32api
import win32con
import win32security

priv_flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY

hToken = win32security.OpenProcessToken (win32api.GetCurrentProcess (), priv_flags)
backup_privilege_id = win32security.LookupPrivilegeValue (None, "SeBackupPrivilege")

restore_privilege_id = win32security.LookupPrivilegeValue (None, "SeRestorePrivilege")
win32security.AdjustTokenPrivileges (

  hToken, 0, [

    (backup_privilege_id, win32security.SE_PRIVILEGE_ENABLED),
    (restore_privilege_id, win32security.SE_PRIVILEGE_ENABLED)
  ]
)

result = _winreg.LoadKey (_winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Office",ur"Office.registry")

print "Restored Office Settings"

here "office.registry" is the backed up hive HKEY_CURRENT_USER\Software\Microsoft\Office

I am getting WindowsError: [Errno 5] Access is denied.

Please help me to identify my mistake

+1  A: 

The registry system has a built-in method for updating registry keys by creating and importing a .reg text file. I suggest that you try to write your changes to a .reg file and import that.

Also, you don't mention what Windows version you are using. In the newer versions, the permission system is rather more complex than it used to be.

Michael Dillon