?
Solved

Registry probs with RegSaveKey

Posted on 2004-09-07
3
Medium Priority
?
753 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 500 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

752 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