Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Exile 1.8 - The Password Manager

, 6 Mar 2005
Yet another password manager.
exile_18_setup.zip
exile_1.8_setup.exe
exile_exe.zip
exile.exe
Exile.exe.manifest
icons.dll
md5.dll
mdx.dll
PwsInfo.dll
rc5.dll
exile_exe_staticmfc.zip
exile.exe
icons.dll
md5.dll
mdx.dll
rc5.dll
exile_src.zip
exile
Exile
Exile.exe.manifest
exile.dep
exile.dsp
exile.dsw
res
aboveimportant.ico
advanced.bmp
belowcritical.ico
belowinsignificant.ico
belownormal.ico
changeicon.bmp
cold.ico
collapsed.ico
critical.ico
editcategory.bmp
editelement.bmp
enterpassword.bmp
error.ico
exile.ico
expanded.ico
exporttoxml.bmp
find.ico
found.ico
important.ico
insertcategory.bmp
insertelement.bmp
insignificant.ico
md5hashgenerator.bmp
new.bmp
normal.ico
options.bmp
passwordgenerator.bmp
rsasecurity.bmp
rsasecurity.ico
search.cur
storageproperties.bmp
switch.bmp
unimportant.ico
veryimportant.ico
vssver.scc
Icons
res
icon1.ico
icon10.ico
icon11.ico
icon12.ico
icon13.ico
icon14.ico
icon15.ico
icon16.ico
icon17.ico
icon18.ico
icon19.ico
icon2.ico
icon20.ico
icon21.ico
icon22.ico
icon23.ico
icon24.ico
icon25.ico
icon26.ico
icon27.ico
icon28.ico
icon3.ico
icon4.ico
icon5.ico
icon6.ico
icon7.ico
icon8.ico
icon9.ico
md5
md5.dep
md5.dsp
mdx
pwsinfo
passwordstorageshellext.rgs
pwsinfo.def
pwsinfo.dep
pwsinfo.dsp
pwsinfo.dsw
PwsInfo.tlb
pwsinfops.def
pwsinfops.mk
rc5
rc5.dep
rc5.dsp
xml
exile_src_vs2003.zip
Exile.exe.manifest
Exile.dep
Exile.dsp
Exile.dsw
Exile.suo
msxml3.tlh
msxml3.tli
res
AboveImportant.ico
Advanced.bmp
BelowCritical.ico
BelowInsignificant.ico
BelowNormal.ico
ChangeIcon.bmp
Cold.ico
Critical.ico
EditCategory.bmp
EditElement.bmp
EnterPassword.bmp
Error.ico
Exile.ico
ExportToXML.bmp
Find.ico
Found.ico
Icon1.ico
Icon10.ico
Icon11.ico
Icon12.ico
Icon13.ico
Icon14.ico
icon15.ico
Icon16.ico
Icon17.ico
Icon18.ico
Icon19.ico
Icon2.ico
Icon20.ico
Icon21.ico
Icon22.ico
Icon23.ico
Icon24.ico
Icon25.ico
Icon26.ico
Icon27.ico
Icon28.ico
Icon3.ico
Icon4.ico
Icon5.ico
Icon6.ico
Icon7.ico
Icon8.ico
Icon9.ico
Important.ico
InsertCategory.bmp
InsertElement.bmp
Insignificant.ico
MD5HashGenerator.bmp
New.bmp
Normal.ico
Options.bmp
PasswordGenerator.bmp
RSASecurity.bmp
rsasecurity.ico
Search.cur
StorageProperties.bmp
Switch.bmp
Unimportant.ico
VeryImportant.ico
vssver.scc
MD5
MD5.dep
MD5.dsp
PwsInfo
PasswordStorageShellExt.rgs
PwsInfo.def
PwsInfo.dep
PwsInfo.dsp
PwsInfo.dsw
PwsInfo.tlb
PwsInfops.def
PwsInfops.mk
RC5
RC5.dep
RC5.dsp
/********************************************************************
	Created:	31/3/2004, 21:49
	File name: 	D:\Projects\Exile\Exile\Registry.cpp
	File path:	D:\Projects\Exile\Exile
	File base:	Registry
	File ext:	cpp
	Author:		Gogolev Anton
*********************************************************************/

#include "StdAfx.h"
#include "Registry.h"
#include "WinReg.h"

#define CLASS_NAME_LENGTH 255;

CRegistry::CRegistry()
{
	m_bDelayedWrite = FALSE;
	m_hRootKey = HKEY_CURRENT_USER;
	m_nLastError = ERROR_SUCCESS;
}

CRegistry::~CRegistry()
{
	ClearKey();
}

BOOL CRegistry::ClearKey()
{
	m_strCurrentPath.Empty();
	m_bDelayedWrite = FALSE;
	m_hRootKey = HKEY_CURRENT_USER;

	return TRUE;
}

BOOL CRegistry::SetRootKey(HKEY hRootKey)
{
	if((hRootKey != HKEY_CURRENT_USER) &&
		(hRootKey != HKEY_LOCAL_MACHINE) &&
		(hRootKey != HKEY_CLASSES_ROOT) &&
		(hRootKey != HKEY_USERS))
		return FALSE;

	m_hRootKey = hRootKey;

	return TRUE;
}

BOOL CRegistry::CreateKey(CString strKey)
{
	if(strKey[0] == '\\')
		return FALSE;

	HKEY hKey;
	DWORD dwDisposition = 0;

	m_nLastError = ::RegCreateKeyEx(m_hRootKey, (LPCTSTR)strKey, 0, NULL,
		REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,
		&dwDisposition);

	if(m_nLastError != ERROR_SUCCESS)
		return FALSE;

	if(!m_bDelayedWrite)
		::RegFlushKey(hKey);
	::RegCloseKey(hKey);

	m_strCurrentPath = strKey;

	return TRUE;
}

BOOL CRegistry::DeleteKey(CString strKey)
{
	if((strKey[0] == '\\') || (strKey.GetLength() == 0))
		return FALSE;

	HKEY hKey;

	m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)strKey, 0,
		KEY_ALL_ACCESS, (PHKEY)&hKey);

	if(m_nLastError != ERROR_SUCCESS)
		return FALSE;

	m_nLastError = ::RegDeleteKey(hKey, (LPCTSTR)strKey);

	return (m_nLastError == ERROR_SUCCESS);
}

BOOL CRegistry::DeleteValue(CString strKey)
{
	if(m_strCurrentPath.GetLength() < 0)
		return FALSE;

	HKEY hKey;

	if(::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_SET_VALUE, (PHKEY)&hKey) != ERROR_SUCCESS)
		return FALSE;

	m_nLastError = ::RegDeleteValue(hKey, (LPCTSTR)strKey);
	::RegCloseKey(hKey);

	if(m_nLastError != ERROR_SUCCESS)
		return FALSE;
	else
		return TRUE;
}

BOOL CRegistry::KeyExists(CString strKeyName, HKEY hRoot)
{
	if(strKeyName[0] == '\\')
		return FALSE;

	HKEY hKey;
	if(hRoot == NULL)
		hRoot = m_hRootKey;

	m_nLastError = ::RegOpenKeyEx(hRoot, (LPCTSTR)strKeyName, 0,
		KEY_ALL_ACCESS, (PHKEY)&hKey);
	::RegCloseKey(hKey);

	return (m_nLastError == ERROR_SUCCESS);
}

BOOL CRegistry::SetKey(CString strKeyName, BOOL bCanCreate)
{
	if(strKeyName[0] == '\\')
		return FALSE;

	HKEY hKey;
	DWORD dwDisposition;

	if(strKeyName.GetLength() == 0)
	{
		m_strCurrentPath.Empty();
		return TRUE;
	}

	if(bCanCreate)
	{
		m_nLastError = ::RegCreateKeyEx(m_hRootKey, (LPCTSTR)strKeyName,
			0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
			(PHKEY)&hKey, &dwDisposition);
	
		if(m_nLastError != ERROR_SUCCESS)
			return FALSE;
		
		m_strCurrentPath = strKeyName;
		
		if(!m_bDelayedWrite)
			::RegFlushKey(hKey);
		
		::RegCloseKey(hKey);
		
		return TRUE;
	}
	else
	{
		m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)strKeyName,
			0, KEY_ALL_ACCESS, (PHKEY)&hKey);
		
		if(m_nLastError != ERROR_SUCCESS)
			return FALSE;

		m_strCurrentPath = strKeyName;
		
		if(!m_bDelayedWrite)
			::RegFlushKey(hKey);
		
		::RegCloseKey(hKey);
		
		return TRUE;
	}
}

double CRegistry::ReadDouble(CString strKeyName, double fDefault)
{
	DWORD dwType = REG_BINARY;
	double fRes;
	DWORD dwSize = sizeof(fRes);
	HKEY hKey;

	ASSERT(m_strCurrentPath.GetLength() > 0);

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_READ, (PHKEY)&hKey)) != ERROR_SUCCESS) return fDefault;

	if (::RegQueryValueEx(hKey, (LPCTSTR)strKeyName, NULL,
		&dwType, (LPBYTE)&fRes, &dwSize) != ERROR_SUCCESS) 
		fRes = fDefault;
	
	::RegCloseKey(hKey);	
	
	return fRes;
}

CString CRegistry::ReadString(CString strKeyName, CString strDefault)
{
	DWORD dwType = REG_SZ;
	DWORD dwSize = 255;
	BOOL bSuccess = TRUE;
	_TCHAR sz[255];
	HKEY hKey;
	
	ASSERT(m_strCurrentPath.GetLength() > 0);

	m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_READ, (PHKEY)&hKey);
	if (m_nLastError != ERROR_SUCCESS) 
		return strDefault;

	m_nLastError = ::RegQueryValueEx(hKey, (LPCTSTR)strKeyName, NULL,
		&dwType, (LPBYTE)sz, &dwSize);
	if (m_nLastError != ERROR_SUCCESS) 
		bSuccess = FALSE;
	::RegCloseKey(hKey);	
	
	if (!bSuccess) 
		return strDefault;

	return CString((LPCTSTR)sz);
}

DWORD CRegistry::ReadDword(CString strKeyName, DWORD dwDefault)
{
	DWORD dwType = REG_DWORD;
	DWORD dwRes;
	DWORD dwSize = sizeof(dwRes);
	HKEY hKey;

	ASSERT(m_strCurrentPath.GetLength() > 0);

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_READ, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return dwDefault;

	if (::RegQueryValueEx(hKey, (LPCTSTR)strKeyName, NULL,
		&dwType, (LPBYTE)&dwRes, &dwSize) != ERROR_SUCCESS) 
		dwRes = dwDefault;
	
	::RegCloseKey(hKey);	
	
	return dwRes;
}

int CRegistry::ReadInt(CString strKeyName, int nDefault)
{
	DWORD dwType = REG_BINARY;
	int nRes;
	DWORD dwSize = sizeof(nRes);
	HKEY hKey;

	ASSERT(m_strCurrentPath.GetLength() > 0);

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_READ, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return nDefault;

	if (::RegQueryValueEx(hKey, (LPCTSTR)strKeyName, NULL,
		&dwType, (LPBYTE)&nRes, &dwSize) != ERROR_SUCCESS) 
		nRes = nDefault;
	
	::RegCloseKey(hKey);	
	
	return nRes;
}

BOOL CRegistry::ReadBool(CString strKeyName, BOOL bDefault)
{
	DWORD dwType = REG_BINARY;
	BOOL bRes;
	DWORD dwSize = sizeof(bRes);
	HKEY hKey;

	ASSERT(m_strCurrentPath.GetLength() > 0);

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_READ, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return bDefault;

	if (::RegQueryValueEx(hKey, (LPCTSTR)strKeyName, NULL,
		&dwType, (LPBYTE)&bRes, &dwSize) != ERROR_SUCCESS) 
		bRes = bDefault;
	
	::RegCloseKey(hKey);	
	
	return bRes;
}

BOOL CRegistry::WriteDouble(CString strKeyName, double fValue)
{
	ASSERT(m_strCurrentPath.GetLength() > 0);
	BOOL bSuccess = TRUE;
	HKEY hKey;

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_WRITE, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return FALSE;
	
	if (::RegSetValueEx(hKey, (LPCTSTR)strKeyName, 0,
		REG_BINARY, (LPBYTE)&fValue, sizeof(fValue)) != ERROR_SUCCESS) 
		bSuccess = FALSE;
		
	if (!m_bDelayedWrite) 
		::RegFlushKey(hKey);
	
	::RegCloseKey(hKey);
	
	return bSuccess;
}

BOOL CRegistry::WriteString(CString strKeyName, CString strValue)
{
	ASSERT(m_strCurrentPath.GetLength() > 0);
	BOOL bSuccess = TRUE;
	HKEY hKey;
	_TCHAR sz[255];
	
	if (strValue.GetLength() > 254) return FALSE;

#ifdef _UNICODE
	wstrcpy(sz, (LPCTSTR)strValue);
#else
	strcpy(sz, (LPCTSTR)strValue);
#endif

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_WRITE, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return FALSE;
	
#ifdef _UNICODE
	if (::RegSetValueEx(hKey, (LPCTSTR)strKeyName, 0,
		REG_SZ, (LPBYTE)sz, wstrlen(sz) + 1) != ERROR_SUCCESS) 
		bSuccess = FALSE;
#else
	if (::RegSetValueEx(hKey, (LPCTSTR)strKeyName, 0,
		REG_SZ, (LPBYTE)sz, strlen(sz) + 1) != ERROR_SUCCESS) 
		bSuccess = FALSE;
#endif
		
	if (!m_bDelayedWrite) 
		::RegFlushKey(hKey);
	
	::RegCloseKey(hKey);
	
	return bSuccess;
}

BOOL CRegistry::WriteDword(CString strKeyName, DWORD dwValue)
{
	ASSERT(m_strCurrentPath.GetLength() > 0);
	BOOL bSuccess = TRUE;
	HKEY hKey;

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_WRITE, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return FALSE;
	
	if (::RegSetValueEx(hKey, (LPCTSTR)strKeyName, 0,
		REG_BINARY, (LPBYTE)&dwValue, sizeof(dwValue)) != ERROR_SUCCESS) 
		bSuccess = FALSE;
		
	if (!m_bDelayedWrite) 
		::RegFlushKey(hKey);
	
	::RegCloseKey(hKey);
	
	return bSuccess;
}

BOOL CRegistry::WriteInt(CString strKeyName, int nValue)
{
	ASSERT(m_strCurrentPath.GetLength() > 0);
	BOOL bSuccess = TRUE;
	HKEY hKey;

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_WRITE, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return FALSE;
	
	if (::RegSetValueEx(hKey, (LPCTSTR)strKeyName, 0,
		REG_BINARY, (LPBYTE)&nValue, sizeof(nValue)) != ERROR_SUCCESS) 
		bSuccess = FALSE;
		
	if (!m_bDelayedWrite) 
		::RegFlushKey(hKey);
	
	::RegCloseKey(hKey);
	
	return bSuccess;
}

BOOL CRegistry::WriteBool(CString strKeyName, BOOL bValue)
{
	ASSERT(m_strCurrentPath.GetLength() > 0);
	BOOL bSuccess = TRUE;
	HKEY hKey;

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_WRITE, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return FALSE;
	
	if (::RegSetValueEx(hKey, (LPCTSTR)strKeyName, 0,
		REG_BINARY, (LPBYTE)&bValue, sizeof(bValue)) != ERROR_SUCCESS) 
		bSuccess = FALSE;
		
	if (!m_bDelayedWrite) 
		::RegFlushKey(hKey);
	
	::RegCloseKey(hKey);
	
	return bSuccess;
}

COleDateTime CRegistry::ReadDateTime(CString strKeyName, COleDateTime &dtDefault)
{
	DWORD dwType = REG_BINARY;
	int anDateTime[6];
	DWORD dwSize = sizeof(anDateTime);
	HKEY hKey;
	COleDateTime dtRes;
	
	ASSERT(m_strCurrentPath.GetLength() > 0);

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_READ, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return dtDefault;

	if (::RegQueryValueEx(hKey, (LPCTSTR)strKeyName, NULL,
		&dwType, (LPBYTE)&anDateTime, &dwSize) != ERROR_SUCCESS) 
		dtRes = dtDefault;
	else
		dtRes.SetDateTime(anDateTime[0], anDateTime[1], anDateTime[2], anDateTime[3], anDateTime[4],
			anDateTime[5]);

	::RegCloseKey(hKey);	
	
	return dtRes;
}

BOOL CRegistry::WriteDateTime(CString strKeyName, COleDateTime &dtValue)
{
	ASSERT(m_strCurrentPath.GetLength() > 0);
	BOOL bSuccess = TRUE;
	HKEY hKey;

	int anDateTime[6];
	
	anDateTime[0] = dtValue.GetYear();
	anDateTime[1] = dtValue.GetMonth();
	anDateTime[2] = dtValue.GetDay();

	anDateTime[3] = dtValue.GetHour();
	anDateTime[4] = dtValue.GetMinute();
	anDateTime[5] = dtValue.GetSecond();

	if ((m_nLastError = ::RegOpenKeyEx(m_hRootKey, (LPCTSTR)m_strCurrentPath, 0,
		KEY_WRITE, (PHKEY)&hKey)) != ERROR_SUCCESS) 
		return FALSE;
	
	if (::RegSetValueEx(hKey, (LPCTSTR)strKeyName, 0,
		REG_BINARY, (LPBYTE)&anDateTime, sizeof(anDateTime)) != ERROR_SUCCESS) 
		bSuccess = FALSE;
		
	if (!m_bDelayedWrite) 
		::RegFlushKey(hKey);
	
	::RegCloseKey(hKey);
	
	return bSuccess;
}

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.

License

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

Share

About the Author

AntonGogolev
Web Developer
Russian Federation Russian Federation
I'll think about it later on...

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 7 Mar 2005
Article Copyright 2004 by AntonGogolev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid