Index: src/chext/DllRegistration.cpp
===================================================================
diff -u -r6609ba39811176f4803f0556db3da30e9e457b9d -r7e67996922421c8b79c7c0d20d4d68c7722c4ad8
--- src/chext/DllRegistration.cpp	(.../DllRegistration.cpp)	(revision 6609ba39811176f4803f0556db3da30e9e457b9d)
+++ src/chext/DllRegistration.cpp	(.../DllRegistration.cpp)	(revision 7e67996922421c8b79c7c0d20d4d68c7722c4ad8)
@@ -56,12 +56,22 @@
 
 	void DeleteSingleValue(HKEY key, const wchar_t* pszKey, const wchar_t* pszValueKey)
 	{
+		TRegistry reg(key, pszKey, false, false);
+		if(reg.IsOpen())
+			reg.DeleteValue(pszValueKey);
+	}
+
+	void CreateNodes(HKEY key, const wchar_t* pszKey, std::wstring strSubKey)
+	{
 		TRegistry reg(key, pszKey, false);
-		reg.DeleteValue(pszValueKey);
+		reg.CreateSubKey(strSubKey.c_str());
 	}
 
 	void CreateNodeWithDefaultValue(HKEY key, const wchar_t* pszKey, const wchar_t* pszSubKey, const wchar_t* pszValue)
 	{
+		// ensure key exists
+		CreateNodes(key, L"", pszKey);
+
 		TRegistry reg(key, pszKey, false);
 		reg.CreateSubKey(pszSubKey);
 
@@ -75,15 +85,10 @@
 
 	void DeleteSingleNode(HKEY key, const wchar_t* pszKey, const wchar_t* pszValueKey)
 	{
-		TRegistry reg(key, pszKey, false);
-		reg.DeleteSubKey(pszValueKey);
+		TRegistry reg(key, pszKey, false, false);
+		if(reg.IsOpen())
+			reg.DeleteSubKey(pszValueKey);
 	}
-
-	void CreateNodes(HKEY key, const wchar_t* pszKey, std::wstring strSubKey)
-	{
-		TRegistry reg(key, pszKey, false);
-		reg.CreateSubKey(strSubKey.c_str());
-	}
 }
 
 DllRegistration::DllRegistration(HMODULE hModule)
Index: src/common/TRegistry.cpp
===================================================================
diff -u -re6380ed876ab438bb19585713b36bc1d400f5d95 -r7e67996922421c8b79c7c0d20d4d68c7722c4ad8
--- src/common/TRegistry.cpp	(.../TRegistry.cpp)	(revision e6380ed876ab438bb19585713b36bc1d400f5d95)
+++ src/common/TRegistry.cpp	(.../TRegistry.cpp)	(revision 7e67996922421c8b79c7c0d20d4d68c7722c4ad8)
@@ -21,34 +21,39 @@
 #include <Shlwapi.h>
 #include <boost/numeric/conversion/cast.hpp>
 
-TRegistry::TRegistry(HKEY key, const wchar_t* pszKey, bool bReadOnly)
+TRegistry::TRegistry(HKEY key, const wchar_t* pszKey, bool bReadOnly, bool bFailIfNotFound)
 {
-	ReOpen(key, pszKey, bReadOnly);
+	ReOpen(key, pszKey, bReadOnly, bFailIfNotFound);
 }
 
 TRegistry::~TRegistry()
 {
-	if(m_hKey)
+	if(IsOpen())
 		RegCloseKey(m_hKey);
 }
 
-void TRegistry::ReOpen(HKEY key, const wchar_t* pszKey, bool bReadOnly /*= true*/)
+void TRegistry::ReOpen(HKEY key, const wchar_t* pszKey, bool bReadOnly, bool bFailIfNotFound)
 {
 	if (!pszKey)
 		throw std::invalid_argument("pszKey");
 
-	if (m_hKey)
+	if (IsOpen())
 		RegCloseKey(m_hKey);
 
 	LSTATUS lStatus = RegOpenKeyEx(key, pszKey, 0, bReadOnly ? KEY_QUERY_VALUE : KEY_ALL_ACCESS, &m_hKey);
 	if (lStatus != ERROR_SUCCESS || m_hKey == nullptr)
-		throw std::runtime_error("Cannot open registry key");
+	{
+		if(bFailIfNotFound || lStatus != ERROR_FILE_NOT_FOUND)
+			throw std::runtime_error("Cannot open registry key");
+	}
 }
 
 void TRegistry::CreateSubKey(const wchar_t* pszKey)
 {
 	if (!pszKey)
 		throw std::invalid_argument("pszKey");
+	if(!IsOpen())
+		throw std::runtime_error("Registry key not open");
 
 	HKEY newKey = nullptr;
 	LSTATUS status = RegCreateKeyEx(m_hKey, pszKey, 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY, nullptr, &newKey, nullptr);
@@ -60,6 +65,8 @@
 {
 	if (!pszKey)
 		throw std::invalid_argument("pszKey");
+	if(!IsOpen())
+		throw std::runtime_error("Registry key not open");
 
 	LSTATUS status = SHDeleteKey(m_hKey, pszKey);
 	if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND)
@@ -70,6 +77,8 @@
 {
 	if (!pszValueKey)
 		throw std::invalid_argument("pszValueKey");
+	if(!IsOpen())
+		throw std::runtime_error("Registry key not open");
 
 	LSTATUS status = RegDeleteValue(m_hKey, pszValueKey);
 	if (status != ERROR_SUCCESS && status != ERROR_FILE_NOT_FOUND)
@@ -80,6 +89,8 @@
 {
 	if (!pszValueKey)
 		throw std::invalid_argument("pszValueKey");
+	if(!IsOpen())
+		throw std::runtime_error("Registry key not open");
 
 	DWORD dwType = REG_SZ;
 	const DWORD stMaxBuffer = 1024;
@@ -100,6 +111,8 @@
 {
 	if (!pszValueKey)
 		throw std::invalid_argument("pszValueKey");
+	if(!IsOpen())
+		throw std::runtime_error("Registry key not open");
 
 	DWORD dwType = REG_DWORD;
 	DWORD dwCount = sizeof(DWORD);
@@ -119,6 +132,8 @@
 		throw std::invalid_argument("pszValueKey");
 	if (!pszValue)
 		throw std::invalid_argument("pszValue");
+	if(!IsOpen())
+		throw std::runtime_error("Registry key not open");
 
 	size_t stValueLen = wcslen(pszValue) + 1;
 	LSTATUS status = RegSetValueEx(m_hKey, pszValueKey, 0, REG_SZ, (const BYTE*)pszValue, boost::numeric_cast<DWORD>(stValueLen * sizeof(wchar_t)));
Index: src/common/TRegistry.h
===================================================================
diff -u -r6609ba39811176f4803f0556db3da30e9e457b9d -r7e67996922421c8b79c7c0d20d4d68c7722c4ad8
--- src/common/TRegistry.h	(.../TRegistry.h)	(revision 6609ba39811176f4803f0556db3da30e9e457b9d)
+++ src/common/TRegistry.h	(.../TRegistry.h)	(revision 7e67996922421c8b79c7c0d20d4d68c7722c4ad8)
@@ -22,11 +22,13 @@
 class TRegistry
 {
 public:
-	TRegistry(HKEY key, const wchar_t* pszKey, bool bReadOnly = true);
+	TRegistry(HKEY key, const wchar_t* pszKey, bool bReadOnly = true, bool bFailIfNotFound = true);
 	~TRegistry();
 
-	void ReOpen(HKEY key, const wchar_t* pszKey, bool bReadOnly = true);
+	bool IsOpen() const { return m_hKey != nullptr; }
 
+	void ReOpen(HKEY key, const wchar_t* pszKey, bool bReadOnly = true, bool bFailIfNotFound = true);
+
 	void CreateSubKey(const wchar_t* pszKey);
 	void DeleteSubKey(const wchar_t* pszKey);