|
|
|
date: Thu, 30 Mar 2006 04:07:39 -0800,
group: microsoft.public.win32.programmer.tools
back
How to use "RegSaveKey"?
Dear all!
I try to make a backup of the registry!
first,I open the key and save the handle like this:
RegOpenKeyEx
(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services",NULL,KEY_ALL_AC
CESS,(PHKEY)&hKey);
then,I try to save it to a txt file:
RegSaveKey(hKey,"f:\\abc.txt",null);
but an error occur:"A required privilege is not held by the client."
all codes:
int _tmain(int argc, _TCHAR* argv[])
{
HKEY hKey;
HLOCAL hlocal = NULL;
DWORD dwError =
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services",NULL,KEY_ALL_ACCESS,(PHKEY)&hKey);
if(dwError == ERROR_SUCCESS)
{
dwError = RegSaveKey(hKey,"f:\\abc.txt",null);
if(dwError == ERROR_SUCCESS)
MessageBox(NULL,"ok!",NULL,MB_OK);
else
{
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, dwError, MAKELANGID(LANG_ENGLISH,
SUBLANG_ENGLISH_US),(PTSTR)&hlocal, 0, NULL);
MessageBox(NULL,(LPCSTR)hlocal,NULL,MB_OK);
}
RegCloseKey(hKey);
}
return 0;
}
date: Thu, 30 Mar 2006 04:07:39 -0800
author: troylees
RE: How to use "RegSaveKey"?
he problem has been solved.The process which calls RegSaveKey must have got
the authority of SE_BACKUP_NAME. See :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/regsavekey.asp
"troylees" wrote:
> Dear all!
> I try to make a backup of the registry!
> first,I open the key and save the handle like this:
> RegOpenKeyEx
> (HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services",NULL,KEY_ALL_AC
> CESS,(PHKEY)&hKey);
>
> then,I try to save it to a txt file:
> RegSaveKey(hKey,"f:\\abc.txt",null);
>
> but an error occur:"A required privilege is not held by the client."
>
> all codes:
> int _tmain(int argc, _TCHAR* argv[])
> {
> HKEY hKey;
> HLOCAL hlocal = NULL;
>
> DWORD dwError =
> RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services",NULL,KEY_ALL_ACCESS,(PHKEY)&hKey);
> if(dwError == ERROR_SUCCESS)
> {
>
>
> dwError = RegSaveKey(hKey,"f:\\abc.txt",null);
>
> if(dwError == ERROR_SUCCESS)
> MessageBox(NULL,"ok!",NULL,MB_OK);
>
> else
> {
> FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |
> FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, dwError, MAKELANGID(LANG_ENGLISH,
> SUBLANG_ENGLISH_US),(PTSTR)&hlocal, 0, NULL);
> MessageBox(NULL,(LPCSTR)hlocal,NULL,MB_OK);
> }
> RegCloseKey(hKey);
> }
> return 0;
> }
>
date: Thu, 30 Mar 2006 08:22:02 -0800
author: troylees
|
|