THIS CLASS - CREGKEY --- IS Used for OPERATE ON Register.if You Want To Get More, please goto www.confach.533.net
Then Click Visual VC , Thank you!
1) .h file
// regkey.h: interface for the cregoo class.////
#if! defined (AFX_REGKEY_H__47138179_D3D9_4608_8C98_CC2C7336B911__included _) # Define AFX_REGKEY_H__47138179_D3D9_4608_8C98_CC2C7336B911__included_
#if _MSC_VER> 1000 # prgma overce # endif //_MSC_VER> 1000
Class CregKey {public: cregKey (); virtual ~ cregkey ();
// attributespublic: operator hkey () const; hkey m_hKey;
// Operationspublic: LONG SetValue (DWORD dwValue, LPCTSTR lpszValueName); LONG QueryValue (DWORD & dwValue, LPCTSTR lpszValueName); LONG QueryValue (LPTSTR szValue, LPCTSTR lpszValueName, DWORD * pdwCount); LONG SetValue (LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
LONG SetKeyValue (LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL); static LONG WINAPI SetValue (HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
LONG Create (HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass = REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE, REGSAM samDesired = KEY_ALL_ACCESS, LPSECURITY_ATTRIBUTES lpSecAttr = NULL, LPDWORD lpdwDisposition = NULL); LONG Open (HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired = KEY_ALL_ACCESS); Long close (); hkey deet (); void attach (hkey hkey); long deletellkey (lpctstr lpszsubkey); long recurse deletekey; long deletevalue (lpctstr lpszvalue);};
#ENDIF /! Defined (AFX_REGKEY_H__47138179_D3D9_4608_8C98_CC2C7336B911__inCluded_)
2) .CPP file
/ ************************************************** *************** / / * * // * regKey.cpp: importation of the cregkey class. * // * * // * this is anclone of the atl creGkey from Microsoft ******************************************************************************************************************************************************************************************************* ********************** / # include "stdafx.h" #include "regKey.h"
#ifdef _debug # undef this_filestatic char this_file [] = __ file __; # Define new debug_new # Endif
CREGKEY :: CREGKEY () {m_hkey = null;}
CregKey :: ~ CREGKEY () {close ();
/ ************************************************** ******************* // * * // * function name: operator hkey * /// * Description: Converts CregKey Object to an hkey. * // * * / / ************************************************** ******************* / CREGKEY :: Operator HKEY () const {return m_hkey;}
/ ************************************************** ******************* // * * // * Function name: detach * // * description: detaches m_hkey from the cregkey Object * // * * // * *********************************************************** ***************** / HKEY CREGKEY:: DETACH () {hkey hkey = m_hKey; m_hKey = null; return hkey;}
/ ************************************************** ******************* // * * // * function name: attach * // * description: attachs registry key handle to cregkeyObject. * // * * // *********************************************************** ****************** / VOID CREGKEY :: attach (hkey hkey) {assert (m_hkey == null); m_hKey = HKEY;
/ ************************************************** ****************** / / * * // * function name: deleteSubkey * // * Description: deletes the specified key. * // * * // ** *********************************************************** **************** / Long CregKey :: deleteSubkey (LPCTSTR LPSZSUBKEY) {assert (m_hKey! = Null); return regdeletekey (m_hKey, lpszsubkey);} / ***** *********************************************************** ************* // * * // * function name: deletevalue * // * Description: deletes a value field of the key Identified by * // * m_hKey. * // * * // ******************************************************** ************************** / Long CregKey :: DeleteValue (LPCTSTR LPSZVALUE) {Assert (m_hkey! = Null); Return RegdeleteValue (M_HKEY, (LPTSTSTR) LPSZVALUE); }
/ ************************************************** ******************* // * * // * function name: close * // * Description: releases m_hKey. * // * * // **** *********************************************************** ************** / long cregkey :: close () {long lres = error_success; if (m_hkey! = Null) {lres = regclosekey (m_hKey); m_hkey = null;} return lres }
/ ************************************************** ******************* // * * // * function name: create * // * description: creates or opens the specified key. * // * * // *********************************************************** ****************** / LONG CRegKey :: Create (HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass, DWORD dwOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecAttr, LPDWORD lpdwDisposition) {ASSERT (hKeyParent ! = NULL); DWORD dw; HKEY hKey = NULL; LONG lRes = RegCreateKeyEx (hKeyParent, lpszKeyName, 0, lpszClass, dwOptions, samDesired, lpSecAttr, & hKey, & dw);! if (lpdwDisposition = NULL) * lpdwDisposition = dw; if (lres == Error_Success) {lres = close (); m_hKey = HKEY;} Return Lres;} / ********************************** *************************************************** / / * * / / * function name : OpenS the specified key. * // * * // ********************************* ********************************************************* / Long CregKey :: Open (HKEY HKEYPARENT, LPCTSTSTR LPSZKEYNAME , Regsam Samdesired) {Assert (HKeyParent) ! = NULL); HKEY hKey = NULL; LONG lRes = RegOpenKeyEx (hKeyParent, lpszKeyName, 0, samDesired, & hKey); if (lRes == ERROR_SUCCESS) {lRes = Close (); ASSERT (lRes == ERROR_SUCCESS); m_hKey = Return lres;}
/ ************************************************** ******************* // * * // * function name: queryValue * // * Description: Retrieves the data for a specified value field. * // * * // ******************************************************** ************************** / Long Cregkey :: QueryValue (DWORD & DWVALUE, LPCTSTSTR LPSZVALUE, LPCTSTSTD DWTYPE = NULL; DWORD DWCOUNT = SIZEOF (DWORD); long lres = RegQueryValueEx (m_hKey, (LPTSTR) lpszValueName, NULL, & dwType, (LPBYTE) & dwValue, & dwCount); ASSERT ((lRes = ERROR_SUCCESS) || (dwType == REG_DWORD)!);! ASSERT ((lRes = ERROR_SUCCESS) || ( DWCOUNT == SizeOf (dword))); return lres;} / **************************************************** ********************************* / / * * // * function name: queryValue * // * Description: RECIEVES The Data For a Specified Value Field. * // * * // ******************************************** **************************************, LPTSTSTSZZVALUE, LPCTSTSTSZZVALUE, LPCTSTSTSZZVALUE, DWORD * PDWCOUNT ) {Assert (pdwcount! = Null); dword dwtype = null; long lres = regqueryvalueex (m_hke y, (LPTSTR) lpszValueName, NULL, & dwType, (LPBYTE) szValue, pdwCount); ASSERT (! (lRes = ERROR_SUCCESS) || (dwType == REG_SZ) || (dwType == REG_MULTI_SZ) || (dwType == REG_EXPAND_SZ )); RETURN LRES;
/ ************************************************** ****************** / / * * // * function name: setValue * // * Description: Stores Data in a specified value field. * // * * / / ************************************************** ****************** / Long WinAPI Cregkey :: SetValue (HKEY HKEYNAME, LPCTSTSTSZZVALUE, LPCTSTSTSTSTSTSR LPSZVALUE, LPCTSTSR LPSZVALUENAME) {Assert (lpszvalue! = Null); CREGKEY Key Long lres = key.create (HKEYPARENT, LPSZKEYNAME); if (lres == error_success) Lres = key.setValue (lpszvalue, lpszvaluename); return lres;} / ************* *********************************************************** **** // * * // * function name: setKeyvalue * /// * Description: Stores Data IN a specified value field of a * // * specified key. * // * * // ****** *********************************************************** ************ / LONG CRegKey :: SetKeyValue (LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName) {ASSERT (lpszValue = NULL!); CRegKey key; LONG lRes = key.Create (m_hKey, lpszKeyName ); if (lres == error_success) Lres = key.setVal UE (lpszvalue, lpszvalueename); Return Lres;}
/ ************************************************** ****************** / / * * // * function name: setValue * // * Description: Stores Data in a specified value field. * // * * / / ************************************************** ****************** / Long CregKey :: setValue (DWORD DWVALUE, LPCTSTSTSZVALUE, LPCTSTSTSZVALUENAME) {Assert (m_hkey! = Null); Return RegsetValueEx (M_HKey, LpszValuename, NULL, REG_DWORD, (Byte * Const) & dwvious, sizeof (dword));
/ ************************************************** ****************** / / * * // * function name: setValue * // * Description: Stores Data in a specified value field. * // * * / / ************************************************** ****************** / Long CregKey :: setValue (lpctstr lpszvalue, lpctstr lpszvalueename) {assert (lpszvalue! = Null); assert (m_hKey! = Null); Return REGSETVALUEEX (M_HKEY, LPSZVALUENAME, NULL, REG_SZ, (BYTE * Const) Lpszvalue, (LSTRLEN (LPSZVALUE) 1) * Sizeof (tchar));} / *************** *********************************************************** ** // * * // * function name: RecursedeeteKey * // * Description: deletes the specified key and explicitly deletes * // * all subkeys. * // * * // ********** *********************************************************** ******** / LONG CRegKey :: RecurseDeleteKey (LPCTSTR lpszKey) {CRegKey key; LONG lRes = key.Open (m_hKey, lpszKey, KEY_READ | KEY_WRITE); if (lRes = ERROR_SUCCESS!) return lRes; FILETIME time DWORD DWSIZE = 256; Tchar Szbuffer [256]; While (RegenumKeyex (Key.m_hKey, 0, SZBuff er, & dwSize, NULL, NULL, NULL, & time) == ERROR_SUCCESS) {lRes = key.RecurseDeleteKey (szBuffer); if (lRes = ERROR_SUCCESS) return lRes;! dwSize = 256;} key.Close (); return DeleteSubKey ( LPSZKEY);