Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / May 2005

Tip: Looking for answers? Try searching our database.

How to do a deep copy of HKEY_LOCAL_MACHINE to HKEY_CURRENT_USER?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave Leach - 18 Oct 2004 19:27 GMT
I am developing an application using Visual Studio.NET 2003 in C++ on XP
Professional.

I need to do a deep copy (recursive) in the Registry from HKEY_LOCAL_MACHINE
to HKEY_CURRENT_USER.  I have tried using the shell function SHCopyKey()
(from shlwapi.dll version 6.0.2800.1552) without success.  It appears to do
nothing and returns no error.

I have experimented with a variety of things (creating the registry key
before doing the copy, flushing the registry key afterward, etc).  I open the
source registry key for 'read' and the destination registry key for 'write'
beforehand.  I'm logged in and running as an Administrator.

It will be painful to have to do the deep copy recursively myself.

Am I missing something that prevents SHCopyKey() from working?
Is there a different function that does the recursive deep copy that I can
use?

Thanks,
Dave
"Peter Huang" - 19 Oct 2004 04:43 GMT
Hi

You may try the code below to see if that works for you.

#include <iostream>
#include <tchar.h>
#include <shlwapi.h>
#include <Windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
    SECURITY_ATTRIBUTES sa;
   sa.nLength = sizeof (SECURITY_ATTRIBUTES);
   sa.lpSecurityDescriptor = NULL;
   sa.bInheritHandle = FALSE;
    HKEY hKeyDst;
    DWORD dwDisposition;
    int rt = RegCreateKeyEx(HKEY_CURRENT_USER,"Clarify",0,"",0,KEY_READ |
KEY_WRITE,&sa,&hKeyDst,&dwDisposition);
    if(!rt)
    {
        rt = SHCopyKeyW(HKEY_LOCAL_MACHINE,L"SOFTWARE\\Clarify",hKeyDst,0);
        RegCloseKey(hKeyDst);
    }
    printf("%d",rt);
    return 0;
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

"Peter Huang" - 21 Oct 2004 02:42 GMT
Hi

Have you tried my suggstion?
IF you still have any concern on this issue please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Pamela - 19 May 2005 14:51 GMT
Hello Peter,

I was trying to use the code you gave below in my Visual Studio 6.0 C++
project to copy over a current folder registry settings (and all sub
folders) from a Current_User to a new folder in Current_user.  I included
the <shlwapi.h> in the file but get the following error message:

error C2065: 'SHCopyKeyW' : undeclared identifier

The version of the shlwapi.dll is 6.0.2800.1612.

Any suggestions?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.