Solved

Registry probs with RegSaveKey

Posted on 2004-09-07
3
747 Views
Last Modified: 2013-12-04
I am having a problem saving a registry to a file using RegSaveKey.
I can open the registry fine but when I try to save it with

    ret= RegSaveKey(hkey,path,NULL);

I get a 1314 return code which is "A required privilege is not held by the client"
I pass in NULL as the LPSECURITY_ATTRIBUTES which should default to the client privs and the key I am reading was placed in by the client as well. I can read and access it just fine its only this function that fails. Any ideas?
0
Comment
Question by:joele23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:mxjijo
ID: 12000172
Take a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/regsavekey.asp

Says

<quote>
The calling process must have the SE_BACKUP_NAME privilege enabled. For more information, see Running with Special Privileges.
Windows Me/98/95:  This platform uses a different registry hive file format than Windows NT. Therefore, you cannot load a registry hive file created on Windows 95/98/Me on Windows NT or vice-versa.
</quote>

So you need to change your won process previlages with SE_BACKUP_NAME
0
 
LVL 8

Accepted Solution

by:
mxjijo earned 125 total points
ID: 12000275

Call the following functionto set the privilage

if (!GrabPrivilage(SE_BACKUP_NAME))
    printf("\nFailed. Cannot set previlage");
else
{
    printf("\nSE_BACKUP_NAME Privilage has been set");

    // Now call RegSaveKey() here...


}


BOOL
GrabPrivilage(LPCTSTR szNewPriv)
{
    TOKEN_PRIVILEGES Priv, PrivOld;
    DWORD cbPriv = sizeof(PrivOld);
    HANDLE hToken;
      DWORD  dwError;

    // get current thread token
    if (!OpenThreadToken(GetCurrentThread(),
                         TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES,
                         FALSE, &hToken))
    {
        if (GetLastError() != ERROR_NO_TOKEN)
            return FALSE;
        // revert to the process token, if not impersonating
        if (!OpenProcessToken(GetCurrentProcess(),
                              TOKEN_QUERY|TOKEN_ADJUST_PRIVILEGES,
                              &hToken))
            return FALSE;
    }

    Priv.PrivilegeCount                        = 1;
    Priv.Privileges[0].Attributes      = SE_PRIVILEGE_ENABLED;
    LookupPrivilegeValue(NULL, szNewPriv, &Priv.Privileges[0].Luid);

    // try to enable the privilege
    if (!AdjustTokenPrivileges(hToken,
                                                FALSE,
                                                &Priv,
                                                sizeof(Priv),
                                                &PrivOld,
                                                &cbPriv))
    {
        dwError = GetLastError();
        CloseHandle(hToken);
        return SetLastError(dwError), FALSE;
    }

    if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
    {
        // the SE_DEBUG_NAME privilege is not in the caller's token
        CloseHandle(hToken);
        return SetLastError(ERROR_ACCESS_DENIED), FALSE;
    }

      return TRUE;
}
0
 
LVL 2

Author Comment

by:joele23
ID: 12000977
very nice
thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Standards for file storage. 3 35
Which Microsoft MSDN Package Is The One I need? 3 51
What is MicroStrategy.NET? 2 80
Please explain "Multi-Tenant Services" 5 108
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question