Solved

Registry probs with RegSaveKey

Posted on 2004-09-07
3
749 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

728 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