Пример #1
2
// Notify of a change in the specified registry key/hive
bool RegKey::NotifyChange(LPCTSTR pszKeyName, DWORD dwNotifyfilter, bool bWatchSubKeys /* = false */, HANDLE hEvent /* = NULL */, HKEY hBaseKey /* = HKEY_CURRENT_USER */)
{
	if (pszKeyName == NULL)
	{
		iLastErrorCode_ = ERROR_BAD_ARGUMENTS;
		return false;
	}

	if (!OpenKey(pszKeyName, false, hBaseKey, NULL))
		return false;

	LONG lRetValue = ERROR_SUCCESS;

	if (hEvent == NULL)
		lRetValue = RegNotifyChangeKeyValue(hTheKey_, bWatchSubKeys, dwNotifyfilter, hEvent, FALSE);
	else
		lRetValue = RegNotifyChangeKeyValue(hTheKey_, bWatchSubKeys, dwNotifyfilter, hEvent, TRUE);

	if (lRetValue == ERROR_CALL_NOT_IMPLEMENTED) // NT ONLY
	{
		iLastErrorCode_ = ERROR_CALL_NOT_IMPLEMENTED;
		return false;
	}

	if (lRetValue != ERROR_SUCCESS)
	{
		iLastErrorCode_ = GetLastError();
		return false;
	}

	iLastErrorCode_ = ERROR_SUCCESS;
	return true;
}
Пример #2
0
int RegReadBytes(TCHAR *valuename, byte *value, int iSize)
{
	static byte dwResult;
	LONG rc;
	DWORD dwType=REG_BINARY;
	DWORD dwSize=sizeof(byte);
	if (g_hkey==NULL)
		rc = OpenKey();
	if (g_hkey != NULL)
	{
		//query the size of the data
		rc = RegQueryValueEx(g_hkey, valuename, NULL, &dwType, NULL, &dwSize);
		if (rc == ERROR_SUCCESS)
		{
			iSize = dwSize;
			byte* bResult=new byte[dwSize];
			rc = RegQueryValueEx(g_hkey, valuename, NULL, &dwType, bResult, &dwSize);
			if (rc == ERROR_SUCCESS)
			{
				CloseKey();
				memcpy(value, bResult, 20);
				delete bResult;
				return rc;
			}
		}
	}
	CloseKey();
	return rc;
}
Пример #3
0
bool 
CKNSettings::setPass(string strPass)
{
    bool bReturn = true;

    m_strPass = strPass;
    
    // If we're using the registry, write the passed string to the Pass subkey

    if(m_bUseRegistry) {

        // If the key is open, close it.

        if(m_hKey)
            CloseKey();

        // Opening the key for writing, so we pass false for the ForRead value.

        if(OpenKey(false)) {
            bReturn = SetRegValue("Pass", strPass);
    
            CloseKey();
        }
    }

    return bReturn;
}
Пример #4
0
bool RegKey::SetKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, const BYTE* pValue, DWORD dwValueLength
	, bool bCreateIfNoExist /* = false */, bool bActive /* = false */
	, HKEY hBaseKey /* = HKEY_CURRENT_USER */, LPCTSTR pszMachineName /* = NULL */)
{
	if (pszValueName == NULL || pValue == NULL || pszKeyName == NULL)
	{
		iLastErrorCode_ = ERROR_BAD_ARGUMENTS;
		return false;
	}

	CloseKey(); // Close current active key and base key if remote

	// Open / create the key
	if (!OpenKey(pszKeyName, bCreateIfNoExist, hBaseKey, pszMachineName))
		return false;

	if (!SetValue(pszValueName, (BYTE*)pValue, dwValueLength))
	{
		if (!bActive)
			CloseKey();
		return false;
	}

	if (!bActive)
		CloseKey(); // Close current active key and base key if remote

	iLastErrorCode_ = ERROR_SUCCESS;
	return true;
}
Пример #5
0
int RegReadByteSize(TCHAR *valuename, int &iSize)
{
	static int dwResult;
	LONG rc;
	DWORD dwType=REG_BINARY;
	DWORD dwSize=sizeof(byte);
	if (g_hkey==NULL)
		rc = OpenKey();
	if (g_hkey != NULL)
	{
		//query the size of the data
		rc = RegQueryValueEx(g_hkey, valuename, NULL, &dwType, NULL, &dwSize);
		if (rc == ERROR_SUCCESS)
		{
			dwResult=dwSize;
			iSize = dwResult;
			rc = iSize;
		}
		else {
			dwSize=0;
			rc=-1;
		}
	}
	return rc;
}
Пример #6
0
bool 
CKNSettings::setPort(int iPort)
{
    bool bReturn = true;

    m_iPort = iPort;
    
    // If we're using the registry, write the passed int to the Port subkey

    if(m_bUseRegistry) {

        // If the key is open, close it.

        if(m_hKey)
            CloseKey();

        // Opening the key for writing, so we pass false for the ForRead value.

        if(OpenKey(false)) {
            bReturn = SetRegValueNum("Port", iPort);
    
            CloseKey();
        }
    }

    return bReturn;
}
Пример #7
0
// Restores a saved registry tree from the specified file to the specified key position
bool RegKey::RestoreRegistry(LPCTSTR pszFileName, LPCTSTR pszKeyName, HKEY hBaseKey /* = HKEY_CURRENT_USER */, LPCTSTR pszMachineName /* = NULL */)
{
	if (pszFileName == NULL || pszKeyName == NULL)
	{
		iLastErrorCode_ = ERROR_BAD_ARGUMENTS;
		return false;
	}

	CloseKey(); // Close current active key and base key if remote

	// Open the key
	if (!OpenKey(pszKeyName, true, hBaseKey, pszMachineName))
		return false;

	LONG lRetValue = RegRestoreKey(hTheKey_, pszFileName, REG_OPTION_NON_VOLATILE);
	if (lRetValue == ERROR_CALL_NOT_IMPLEMENTED) // NT ONLY
	{
		iLastErrorCode_ = ERROR_CALL_NOT_IMPLEMENTED;
		return false;
	}

	if (lRetValue != ERROR_SUCCESS)
	{
		iLastErrorCode_ = GetLastError();
		return false;
	}

	iLastErrorCode_ = ERROR_SUCCESS;
	return true;
}
Пример #8
0
LSTATUS APIENTRY RegTree::RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
{	
	Console::GetInstance().Print(L"RegOpenKeyExW: %.8X, %s\n", hKey, lpSubKey);
	
	RegPath path;
	if (ResolveKey(hKey, lpSubKey, path))
	{
		RegNode *node = OpenKey(path);
		if (node != NULL)
		{
			HKEY resultKey = node->AsKey();
			if (IsVirtualKey(resultKey))
			{
				*phkResult = resultKey;
				return ERROR_SUCCESS;
			}
			else
				return Real_RegOpenKeyExW(resultKey, NULL, ulOptions, samDesired, phkResult);
		}
		else
			return ERROR_NOT_FOUND;
	}
	else
		return Real_RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult);
}
Пример #9
0
/*
	subKey を指定した場合は subkey を含むキー以下を削除
	subkey が NULL の場合、カレント の配下を削除
*/
BOOL TRegistry::DeleteChildTree(LPSTR subKey)
{
	char	buf[100];
	BOOL	ret = TRUE;

	if (subKey != NULL && OpenKey(subKey) != TRUE)
		return	FALSE;

	while (EnumKey(0, buf, sizeof(buf)))
	{
		if ((ret = DeleteChildTree(buf)) != TRUE)
			break;
	}
	if (subKey != NULL)
	{
		CloseKey();
		ret = DeleteKey(subKey) ? ret : FALSE;
	}
	else {
		while (EnumValue(0, buf, sizeof(buf)))
		{
			if (DeleteValue(buf) != TRUE)
			{
				ret = FALSE;
				break;
			}
		}
	}
	return	ret;
}
Пример #10
0
// Opens a key, deletes a value from the key and makes key active if required
bool RegKey::DeleteKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, bool bActive /* = false */, HKEY hBaseKey /* = HKEY_CURRENT_USER */, LPCTSTR pszMachineName /* = NULL */)
{
	if (pszValueName == NULL || pszKeyName == NULL)
	{
		iLastErrorCode_ = ERROR_BAD_ARGUMENTS;
		return false;
	}

	CloseKey(); // Close current active key and base key if remote

	// Open the key
	if (!OpenKey(pszKeyName, false, hBaseKey, pszMachineName))
		return false;

	if (!DeleteValue(pszValueName))
	{
		if (!bActive)
			CloseKey();
		return false;
	}

	if (!bActive)
		CloseKey(); // Close current active key and base key if remote

	iLastErrorCode_ = ERROR_SUCCESS;
	return true;
}
Пример #11
0
/*lint -e774 */
bool RegKey::GetKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, BYTE& pValue, DWORD dwValueLength
	, bool bActive /* = false */, HKEY hBaseKey /* = HKEY_CURRENT_USER */, LPCTSTR pszMachineName /* = NULL */)
{
	if ((pszKeyName == NULL) || (pszValueName == NULL) || (&pValue == NULL))
	{
		iLastErrorCode_ = ERROR_BAD_ARGUMENTS;
		return false;
	}

	CloseKey(); // Close current active key and base key if remote

	// Open the key
	if (!OpenKey(pszKeyName, false, hBaseKey, pszMachineName))
		return false;

	if (!GetValue(pszValueName, pValue, dwValueLength))
	{
		if (!bActive)
			CloseKey();
		return false;
	}

	if (!bActive)
		CloseKey(); // Close current active key and base key if remote

	iLastErrorCode_ = ERROR_SUCCESS;
	return true;
}
Пример #12
0
bool 
CKNSettings::GetSettingsFromRegistry()
{
    // If opening the key for reading succeeds, get the registry values for
    // Server, Path, User, and Pass, and store them in their appropriate
    // variables.

    if(OpenKey(true)) 
    {
        if(GetRegValue("Server", m_strServer) && 
           GetRegValueNum("Port", (DWORD&) m_iPort) && 
           GetRegValue("Path", m_strPath) && 
           GetRegValue("User", m_strUser) && 
           GetRegValue("Pass", m_strPass))
        {
            // If getting all of the above values succeeds, close the key

            CloseKey();

            return true;
        }
    }

    return false;
}
Пример #13
0
// Saves a registry tree into the specified file/path from the specified key position
bool RegKey::SaveRegistry(LPCTSTR pszFileName, LPCTSTR pszKeyName, HKEY hBaseKey /* = HKEY_CURRENT_USER */, LPCTSTR pszMachineName /* = NULL */)
{
	if (pszFileName == NULL || pszKeyName == NULL)
	{
		iLastErrorCode_ = ERROR_BAD_ARGUMENTS;
		return false;
	}

	CloseKey(); // Close current active key and base key if remote

	// Open the key
	if (!OpenKey(pszKeyName, false, hBaseKey, pszMachineName))
		return false;

	LONG lRetValue = RegSaveKey(hTheKey_, pszFileName, NULL);

	if (lRetValue == ERROR_ALREADY_EXISTS || lRetValue == ERROR_REGISTRY_IO_FAILED) // Win NT / Win 95
	{
		iLastErrorCode_ = ERROR_ALREADY_EXISTS;
		return false;
	}

	if (lRetValue != ERROR_SUCCESS)
	{
		iLastErrorCode_ = GetLastError();
		return false;
	}

	iLastErrorCode_ = ERROR_SUCCESS;
	return true;
}
Пример #14
0
CNCSPrefsWin::CNCSPrefsWin( bool bUserPref )
{
	m_bUserPref = bUserPref;

	//Create default key
	CNCSPrefsKey *pSoftwareKey = OpenKey( "Software\\Earth Resource Mapping\\Image Web Server", true );
	if( pSoftwareKey ) {
		delete pSoftwareKey;
	}
}
Пример #15
0
HKEY GetModuleKey(HKEY basekey, const char* proc_name, bool writable, bool create) {
	// Work out the registry key to save this under
	if (!sModulePrefs) {
		sModulePrefs = (char *) malloc(strlen(proc_name) + 1);
		if (sModulePrefs == NULL)
			return FALSE;
		strcpy(sModulePrefs, proc_name);
	}
	
	// Check whether the library's entry exists!
	const char* appPath[] = {szSoftware, szCompany, szProfile, 0};
	HKEY appKey = OpenKey(basekey, appPath, writable, create);
	if (!appKey)
		return NULL;
	
	// Attempt to open the registry section for the application
	const char* modPath[] = {sPrefSegment, sModulePrefs, 0};
	HKEY modKey = OpenKey(appKey, modPath, writable, false);
	if (!modKey) {
		// Cut off the app directory and just use the name
		char *file_name = NameFromPath(proc_name);
		
		if (!file_name)
		{
			RegCloseKey(appKey);
			return NULL;
		}
		
		// Adjust the moduleprefs name
		strcpy(sModulePrefs, file_name);
		free(file_name);
		
		// Now get the module key again
		const char* modPath2[] = {sPrefSegment, sModulePrefs, 0};
		modKey = OpenKey(appKey, modPath2, writable, create);
	}
	
	RegCloseKey(appKey);
	
	return modKey;
}
Пример #16
0
QString FhoReg::GetKeyDefaultValue(HKEY parentKey, QString &parentSubKeyName) {
	HKEY k = OpenKey(parentKey, parentSubKeyName, KEY_QUERY_VALUE);

	QString value;

	if (k != 0) {
		value = GetKeyDefaultValue(k);

		CloseKey(k);
	}

	return value;
}
Пример #17
0
layer_c::layer_c(char * exefile,char * layer)
{
  OpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers");
  data = new char[512];
  DWORD asize = 512;
  if (QueryValue(exefile,data,&asize) == 1) {
    asize = 0;
    data[0] = 0;
  };
  SetValue(exefile, layer);
  value = new char[strlen(exefile)+5];
  sprintf(value,"%s",exefile);
  value[strlen(exefile)] = 0;
}
Пример #18
0
int RegWriteDword(TCHAR *valuename, DWORD *value)
{
	LONG rc=0;
	if (g_hkey==NULL)
		rc = OpenKey();
	rc = RegSetValueEx(	g_hkey, 
						valuename, 
						NULL,
						REG_DWORD, 
						(LPBYTE) value,
						sizeof(DWORD)); 
 
	return rc;
}
Пример #19
0
LONG CRegKey::OpenKey(HKEY hKey,LPCWSTR lpszSubKey,DWORD fStatus,LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
	if (!IsUnicodeSystem())
		return OpenKey(hKey,W2A(lpszSubKey),fStatus,lpSecurityAttributes);

	REGSAM  samDesired=0;
	DWORD  fdwOptions;
	LONG ret;
	if (m_hKey!=NULL)
	{
		RegCloseKey(m_hKey);
		DebugCloseHandle(dhtRegKey,&m_hKey,lpszSubKey);
	}
	if (fStatus==samAll)
		samDesired=KEY_ALL_ACCESS;
	else
	{
		if (fStatus&samCreateLink)
			samDesired|=KEY_CREATE_LINK;
		if (fStatus&samCreateSubkey)
			samDesired|=KEY_CREATE_SUB_KEY;
		if (fStatus&samEnumerateSubkeys)
			samDesired|=KEY_ENUMERATE_SUB_KEYS;
		if (fStatus&samExecute)
			samDesired|=KEY_EXECUTE;
		if (fStatus&samNotify)
			samDesired|=KEY_NOTIFY;
		if (fStatus&samQueryValue)
			samDesired|=KEY_QUERY_VALUE;
		if (fStatus&samSetValue)
			samDesired|=KEY_SET_VALUE;
	}
	if (fStatus&optionVolatile)
		fdwOptions=REG_OPTION_VOLATILE;
	else
		fdwOptions=REG_OPTION_NON_VOLATILE;
	if (fStatus&openExist)
		ret=RegOpenKeyExW(hKey,lpszSubKey,0,samDesired,&m_hKey);
	else
	{
		DWORD type;
		ret=RegCreateKeyExW(hKey,lpszSubKey,0,NULL,fdwOptions,samDesired,lpSecurityAttributes,&m_hKey,&type); 
	}
	if (ret!=ERROR_SUCCESS)
		m_hKey=NULL;
	else
		DebugOpenHandle(dhtRegKey,m_hKey,lpszSubKey);
	return ret;
}
Пример #20
0
void CConfigurationCheck::CheckForMissingActivePerl()
{
	CString p_szKeyAP = "SOFTWARE\\Activestate\\ActivePerl\\";

	if (!OpenKey("HKLM", p_szKeyAP))
	{
		OH_MessageBox("Unable to detect\n"
			"ActiveState ActivePerl.\n"
			"\n"
			"This version is required for Perl users.\n"
			"if you don't use Perl you may turn this warning off\n"
			"by not loading the perl interpreter by default.",
			"Caution: ActivePerl missing", MB_OK|MB_ICONWARNING);
	}
}
Пример #21
0
int RegWriteStr(TCHAR *valuename, TCHAR *str)
{
	LONG rc=0;
	if (g_hkey==NULL)
		rc = OpenKey();
	TCHAR txt[MAX_PATH+1];
	wcscpy(txt, str);
	rc = RegSetValueEx(	g_hkey, 
						valuename, 
						NULL,
						REG_SZ, 
						(LPBYTE)txt,
						(wcslen(txt) + 1) * sizeof(txt[0]));
 	return rc;
}
Пример #22
0
int RegWriteBytes(TCHAR *valuename, byte* value, int iSize)
{
	LONG rc=0;
	byte* b = value;
	if (g_hkey==NULL)
		rc = OpenKey();
	rc = RegSetValueEx(	g_hkey, 
						valuename, 
						NULL,
						REG_BINARY, 
						b,
						iSize); 
 
	return rc;
}
Пример #23
0
int RegWriteByte(TCHAR *valuename, byte value)
{
	LONG rc=0;
	byte b = value;
	if (g_hkey==NULL)
		rc = OpenKey();
	rc = RegSetValueEx(	g_hkey, 
						valuename, 
						NULL,
						REG_BINARY, 
						&b,
						sizeof(byte)); 
 
	return rc;
}
Пример #24
0
QStringList* FhoReg::EnumSubKeys(HKEY parentKey, QString &parentSubKeyName) {
	QStringList *resultList;

	HKEY k = OpenKey(parentKey, parentSubKeyName, KEY_ENUMERATE_SUB_KEYS);
	
	if (k != 0) {
		resultList = EnumSubKeys(k);

		CloseKey(k);
	} else {
		resultList = new QStringList();
	}

	return resultList;
}
Пример #25
0
int ReadBuildNumber(TCHAR *szBuildNumber)
{
	HKEY oldKey=g_hkey;
	wsprintf(szBuildNumber, L"unknown");
	int ec;
	ec = OpenKey(L"Platform");
	if (ec == ERROR_SUCCESS)
	{
		ec = RegReadStr(L"Software Build Number", szBuildNumber);
		g_hkey=oldKey;
		return ec;
	}
	else
	{
		g_hkey=oldKey;
		return ec;
	}
}
Пример #26
0
int ReadPlatformName(TCHAR *szPlatformName)
{
	HKEY oldKey=g_hkey;
	wsprintf(szPlatformName, L"unknown");
	int ec;
	ec = OpenKey(L"Platform");
	if (ec == ERROR_SUCCESS)
	{
		ec = RegReadStr(L"Name", szPlatformName);
		g_hkey=oldKey;
		return ec;
	}
	else
	{
		g_hkey=oldKey;
		return ec;
	}
}
Пример #27
0
//RegReadDword
int RegReadDword(TCHAR *valuename, DWORD *value)
{
	static DWORD dwResult;
	LONG rc;
	DWORD dwType=REG_DWORD;
	DWORD dwSize=sizeof(DWORD);
	if (g_hkey==NULL)
		rc = OpenKey();
	if (g_hkey != NULL)
	{
		rc = RegQueryValueEx(g_hkey, valuename, NULL, &dwType, (LPBYTE) value, &dwSize);
		if (rc == ERROR_SUCCESS)
		{
			CloseKey();
			//*value = dwResult;
			return rc;
		}
	}
	CloseKey();
	return rc;
}
Пример #28
0
QStringList* FhoReg::EnumValues(HKEY parentKey, QString &parentSubKeyName) {
	QStringList *resultList = new QStringList();

	HKEY k = OpenKey(parentKey, parentSubKeyName, KEY_QUERY_VALUE);
	
	if (k != 0) {
		DWORD idx = 0;
		TCHAR valueName[maxSize];
        BYTE valueData[maxSize];

		LONG l;
		do {
			DWORD size = maxSize;
			DWORD size2 = maxSize;
			DWORD type;
			l = RegEnumValue(k,
							 idx,
							 valueName,
							 &size,
							 NULL,
							 &type,
							 valueData,
							 &size2);

			if (l == ERROR_SUCCESS) {
                QString name = QString::fromWCharArray(valueName);
                QString data = QString::fromUtf16((const ushort*) valueData);

				resultList->append(data);
			}

			idx++;
		} while (l != ERROR_NO_MORE_ITEMS);

		CloseKey(k);
	}

	return resultList;
}
Пример #29
0
int RegReadByte(TCHAR *valuename, byte *value)
{
	static byte dwResult;
	LONG rc;
	DWORD dwType=REG_BINARY;
	DWORD dwSize=sizeof(byte);
	if (g_hkey==NULL)
		rc = OpenKey();
	if (g_hkey != NULL)
	{
		
		rc = RegQueryValueEx(g_hkey, valuename, NULL, &dwType, &dwResult, &dwSize);
		if (rc == ERROR_SUCCESS)
		{
			CloseKey();
			*value = dwResult;
			return rc;
		}
	}
	CloseKey();
	return rc;
}
Пример #30
0
DWORD RegKey::GetSizeOfValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, HKEY hBaseKey /* = HKEY_CURRENT_USER */, LPCTSTR pszMachineName /* = NULL */)
{
	if (pszValueName == NULL || pszKeyName == NULL)
	{
		iLastErrorCode_ = ERROR_BAD_ARGUMENTS;
		return false;
	}

	DWORD dwCount = 0;
	if (OpenKey(pszKeyName, false, hBaseKey, pszMachineName))
	{
		DWORD dwType = 0;
		DWORD dwValueLength = 0;

		LONG lRetValue = RegQueryValueEx(hTheKey_, pszValueName, NULL, &dwType, NULL, &dwValueLength);
		if (lRetValue == ERROR_SUCCESS || lRetValue == ERROR_MORE_DATA)
			dwCount = dwValueLength / sizeof(TCHAR);

		CloseKey(); // Close it as we have finnished
	}

	return dwCount;
}