1. Read the Registry
// Read the Registry
CString ReadRegisteTable (CString root, CString path, CString key)
{
HKEY hAppKey;
LPCTSTR WINDS_SERVICE_REGISTRY_KEY = path;
LPCTSTR DATA_FILE_SUB_KEY = key;
Char szDataFile [80];
If (root = "HKEY_LOCAL_MACHINE ")
{
If (ERROR_SUCCESS = RegOpenKeyEx (
HKEY_LOCAL_MACHINE,
WINDS_SERVICE_REGISTRY_KEY,
0,
KEY_READ,
& HAppKey ))
{
ULONG cbSize = MAX_PATH * sizeof (TCHAR );
DWORD dwFlag = RegQueryValueEx (
HAppKey,
DATA_FILE_SUB_KEY,
NULL,
NULL,
(LPBYTE) szDataFile, & cbSize );
RegCloseKey (hAppKey );
If (ERROR_SUCCESS = dwFlag)
{
CString strDate = szDataFile; // MessageBox (strDate );
If (strDate. GetLength ()> 0) return strDate;
Else return "";
}
Return "";
}
}
If (root = "HKEY_CURRENT_USER ")
{
If (ERROR_SUCCESS = RegOpenKeyEx (
HKEY_CURRENT_USER,
WINDS_SERVICE_REGISTRY_KEY,
0,
KEY_READ,
& HAppKey ))
{
ULONG cbSize = MAX_PATH * sizeof (TCHAR );
DWORD dwFlag = RegQueryValueEx (
HAppKey,
DATA_FILE_SUB_KEY,
NULL,
NULL,
(LPBYTE) szDataFile, & cbSize );
RegCloseKey (hAppKey );
If (ERROR_SUCCESS = dwFlag)
{
CString strDate = szDataFile; // MessageBox (strDate );
If (strDate. GetLength ()> 0) return strDate;
Else return "";
}
Return "";
}
}
Return "";
} [Nextqage]
2. Write the Registry
// Modify the Registry
BOOL ModifyRegisteTable (CString root, CString path, CString key, CString value)
{
HKEY hAppKey;
DWORD dwDisposition = MAX_PATH * sizeof (TCHAR );
LPCTSTR WINDS_SERVICE_REGISTRY_KEY = path;
LPCTSTR DATA_FILE_SUB_KEY = key;
Char szDataFile [80]; strcpy (szDataFile, value );
If (root = "HKEY_LOCAL_MACHINE ")
{
If (ERROR_SUCCESS! = RegCreateKeyEx (
HKEY_LOCAL_MACHINE,
WINDS_SERVICE_REGISTRY_KEY,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
& HAppKey,
& DwDisposition ))
{
Return false;
}
Else
{
If (ERROR_SUCCESS! = RegSetValueEx (hAppKey,
DATA_FILE_SUB_KEY,
0,
REG_SZ,
(LPBYTE) szDataFile,
(Lstrlen (szDataFile) + 1) * sizeof (TCHAR )))
{
Return false;
}
RegCloseKey (hAppKey );
}
}
If (root = "HKEY_CURRENT_USER ")
{
If (ERROR_SUCCESS! = RegCreateKeyEx (
HKEY_CURRENT_USER,
WINDS_SERVICE_REGISTRY_KEY,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
& HAppKey,
& DwDisposition ))
{
Return false;
}
Else
{
If (ERROR_SUCCESS! = RegSetValueEx (hAppKey,
DATA_FILE_SUB_KEY,
0,
REG_SZ,
(LPBYTE) szDataFile,
(Lstrlen (szDataFile) + 1) * sizeof (TCHAR )))
{
Return false;
}
RegCloseKey (hAppKey );
}
}
Return true;
}