Link to home
Start Free TrialLog in
Avatar of lolik121999
lolik121999

asked on

registry

I'm using RegRestoreKey, and the function fails on
error number 1314. I use it as an administrator and
while writing to a key in which I have full control.
help ?
Avatar of jkr
jkr
Flag of Germany image

The user you're using it with has to hold 'SE_RESTORE_NAME', which is not automatically granted for Administrators, just bot Backup Operators. Go to the user manager and set this privilege manually (Policies -> Privileges). The clear text name is "SeRestorePrivilege". This can also be done programmatically, but is quite a hassle.

Feel free to ask if you need more information!
Avatar of lolik121999
lolik121999

ASKER

I tried this, but it still doesn't work.
I even added my user to Backup Operators group and
it's still giving me error 1314.
Hi,
 Why dont you set and disable the previliges using the
1. SetPrivilege();
2. LookupPrivilegeValue();
3. AdjustTokenPrivileges();

functions???

See MSDN for further details.
Or shall i paste its conetnt here???

Just a hint,
Hope this is useful
Bye,
ABdij
Abdij is (almost) right, sometimes it is necessary to also *enable* that privilege, e.g.

BOOL    EnablePriv  (   BOOL    bEnable)
{
   HANDLE           hToken;
   TOKEN_PRIVILEGES tp;

   if   (   !OpenProcessToken   (   GetCurrentProcess   (),
                                    TOKEN_ADJUST_PRIVILEGES,
                                    &hToken
                                )
        )   return  (   FALSE);


   tp.PrivilegeCount    =   1;
   
   LookupPrivilegeValue (   NULL,
                            SE_RESTORE_NAME,
                            &tp.Privileges  [   0].Luid
                        );

   tp.Privileges    [   0].Attributes   =       bEnable
                                            ?   SE_PRIVILEGE_ENABLED
                                            :   0;

   AdjustTokenPrivileges    (   hToken,
                                FALSE,
                                &tp,
                                sizeof  (   tp),
                                NULL,
                                NULL
                            );

   return   (   GetLastError()  ==   ERROR_SUCCESS);
}
jkr, thank u for the code, it really helped.
just ask a question and u get the points.
abdij : thank u too.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial