Click here to Skip to main content
13,257,667 members (69,748 online)
Click here to Skip to main content


20 bookmarked
Posted 23 Aug 2004

Very secure method to save and restore registry

, 23 Aug 2004
This article gives a very secure method to save and restore registry keys. It provides a ready to use tool in both command-line and UI modes.
// RegSR.h : main header file for the REGSR application
//	Author:		A.YEZZA
//	Date:		August 2004
//	Subject:	Save/Restore registry keys in very safe mode
//	Comment:	Use with your own risk
//	Licence:	This code and application are free. The only 
//				condition is preserving author name			

#if !defined(AFX_REGSR_H__C1C474B1_CABA_44B7_961B_DD6E97FCD3B9__INCLUDED_)
#define AFX_REGSR_H__C1C474B1_CABA_44B7_961B_DD6E97FCD3B9__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH

//	Constants
//	Registry hives strings
#define	HKCU		"HKCU"
#define	HKLM		"HKLM"

//	Config file sections
#define SEC_CRC32		"CRC32"	

#define	DATA_SERVER_PATH	"ServerPath"	//location where we (save to)/(retore from) registry data files 
#define DATA_CONFIG_FILE	"ConfigFile"	//Config file name should be saved in DATA_SERVER_PATH

#include "resource.h"		// main symbols

struct	CmdParams{
	CString	Op;
	CString	Root;
	CString	KeyPath;
	CString	InOutFile;
	CString ConfigFile;

struct FileCRC32{
	CString	FileName;	//File name with its path 
	CString	CRC32;		//File CRC32
	CString	hHive;		//Handle to the hive of the key corresponding to the saved file
	CString	KeyPath;	//Key path without its hive	
	CString	ServerPath; //location where we (save to)/(retore from) registry data files 
	CString	ConfigFile; //Config file name should be saved in ServerPath

// CRegSRApp:
// See RegSR.cpp for the implementation of this class

class CRegSRApp : public CWinApp
	CmdParams	Params;
	CString		ServerPath;	//server path where config file is saved
	CString		ConfigFile; //Cofig file containing correspondance between keys/data files
							//and CRC files
	FileCRC32	SavResFile;

	void SetParams(CmdParams &Params, int &ParamsNum);
	void DoSaveRestore(DWORD	&RetErr);
// Overrides
	// ClassWizard generated virtual function overrides
	virtual BOOL InitInstance();

// Implementation

		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !

	void GetParams(CString& CmdLine, int &ParamsNum);
	void SetSavResFile();
	HKEY	GetHiveFromString(LPCSTR strHive);
	BOOL	IsFileExist(LPCSTR FilePath);
	BOOL	IsKeyExist(HKEY hRoot, LPCSTR KeyPath);
	BOOL	SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege);
	//void Set_FileName(CString &Root, CString	&SubKey);
	BOOL Get_CRC32();
	//void Get_hHive(CString		&str);
	//void Get_KeyPath(CString	&str);
	void Usage();
	void GetSettings();
	BOOL CheckIntegrity(CString &Root, CString &SubKey, CString &InFile);
	BOOL RestoreRegKeyPath(CString &Root, CString &SubKey, CString &InFile, DWORD	&RetError);
	BOOL SaveRegKeyPath(CString &Root, CString &SubKey, CString &OutFile, DWORD	&RetError);
	CString		AddBackSlash(CString &strPath);
	CString		GetFileDirectory(CString &FilePathName);


// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_REGSR_H__C1C474B1_CABA_44B7_961B_DD6E97FCD3B9__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
France France
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 24 Aug 2004
Article Copyright 2004 by JOHN11
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid