Exemplo n.º 1
0
BOOL MRegistryBase::ConnectRemote(LPCSTR asServer, LPCSTR asLogin /*= NULL*/, LPCSTR asPassword /*= NULL*/, LPCSTR asResource /*= NULL*/)
{
	wchar_t szServer[MAX_PATH+2], szLogin[MAX_PATH], szPassword[MAX_PATH], szResource[MAX_PATH];
	szServer[0] = szLogin[0] = szPassword[0] = szResource[0] = 0;
	if (asServer && *asServer) lstrcpy_t(szServer, countof(szServer), asServer);
	if (asLogin && *asLogin) lstrcpy_t(szLogin, countof(szLogin), asLogin);
	if (asPassword && *asPassword) lstrcpy_t(szPassword, countof(szPassword), asPassword);
	if (asResource && *asResource) lstrcpy_t(szResource, countof(szResource), asResource);
	return ConnectRemote(szServer, szLogin, szPassword, szResource);	
}
Exemplo n.º 2
0
// Opens/Creates a key and make it the active key
bool RegKey::OpenKey(LPCTSTR pszKeyName, bool bCreateIfNoExist /* = false */, HKEY hBaseKey /* = HKEY_CURRENT_USER */, LPCTSTR pszMachineName /* = NULL */)
{
	if (pszKeyName == NULL)
	{
		iLastErrorCode_ = ERROR_BAD_ARGUMENTS;
		return false;
	}

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

	// If a computer name is specified, then connect to it...
	if (pszMachineName != NULL)
	{		// This will set up the base key to point to the remote machine
		if (ConnectRemote((HKEY)hBaseKey, pszMachineName) == false) // Try to connect
			return false;
	}
	else
		hBaseKey_ = hBaseKey; // Base key is same as the passed parameter

	LONG lRetValue = ERROR_SUCCESS;

	if (bCreateIfNoExist) // Create ?
	{
		DWORD dwDisp; // Disposition

		lRetValue = RegCreateKeyEx(hBaseKey_, pszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE
			, KEY_ALL_ACCESS, NULL, &hTheKey_, &dwDisp);
	}
	else
		lRetValue = RegOpenKeyEx(hBaseKey_, pszKeyName, NULL, KEY_ALL_ACCESS, &hTheKey_);

	if (lRetValue != ERROR_SUCCESS)
	{
		iLastErrorCode_ = GetLastError();
		hTheKey_ = NULL;

		return false;
	}

	iLastErrorCode_ = ERROR_SUCCESS;
	return true;
}