Exemple #1
0
std::wstring RegistryHelper::readValue(const LPTSTR valueName) const
{
    ATL::CRegKey regKey;
    unsigned long valSize = 0;
    std::wstring value;
    if (!(
            ERROR_SUCCESS == regKey.Open(key_, keyName_, KEY_READ) &&
            ERROR_SUCCESS == regKey.QueryStringValue(valueName, NULL, &valSize) && valSize > 0 &&
            (value.resize(valSize), ERROR_SUCCESS == regKey.QueryStringValue(valueName, (LPTSTR)value.data(), &valSize))
        ))
        value.clear();
    else
        value.resize(valSize - 1);
    return value;
}
Exemple #2
0
bool GetGreenShiledExeFilePath(wchar_t* buffer, std::size_t bufferLength)
{
	ATL::CRegKey key;
	if(key.Open(HKEY_LOCAL_MACHINE, L"Software\\ADClean", KEY_QUERY_VALUE) != ERROR_SUCCESS) {
		return false;
	}
	ULONG size = bufferLength;
	return key.QueryStringValue(L"Path", buffer, &size) == ERROR_SUCCESS;
}
Exemple #3
0
CMainWizard::CMainWizard(CWnd* pOwnerWnd):
CCustomPropSheet(AFX_IDS_APP_TITLE, pOwnerWnd)
{
	CUpdateItApp* pApp = DYNAMIC_DOWNCAST(CUpdateItApp, AfxGetApp());
	ASSERT_VALID(pApp);

	// assign CRT locale
	static const TCHAR szDefLocale[] = _T("English_USA.1252");
	_tsetlocale(LC_ALL, pApp->GetProfileString(SZ_REGK_LOCALE, SZ_REGV_LOCALE_LC_ALL, szDefLocale));

	// load dialog's icons
	m_hIcon = pApp->LoadIcon(IDI_APP_ICON);
	m_hSmIcon = pApp->LoadSmIcon(MAKEINTRESOURCE(IDI_APP_ICON));

	static HYPERLINKCOLORS linkColors =
	{
		RGB(0, 0, 255),	// default
		RGB(0, 0, 255),	// active
		RGB(0, 0, 255),	// visited
		RGB(255, 0, 0)		// hover
	};
	CHyperLink::SetColors(linkColors);

	ATL::CRegKey regKeyLangs;
	regKeyLangs.Attach(pApp->GetSectionKey(SZ_REGK_LANGUAGES));

	int nError = ERROR_SUCCESS;

	if (static_cast<HKEY>(regKeyLangs) != NULL)
	{
		TCHAR szLangNames[128] = { 0 };
		ULONG cchNamesMax = _countof(szLangNames);
		nError = regKeyLangs.QueryStringValue(NULL, szLangNames, &cchNamesMax);
		if (nError == ERROR_SUCCESS)
		{
			LPCTSTR pszSeps = _T(",;\x20");
			LPTSTR pszCurLex = _tcstok(szLangNames, pszSeps);
			while (pszCurLex != NULL)
			{
				m_arrLangNames.Add(pszCurLex);
				pszCurLex = _tcstok(NULL, pszSeps);
			}
		}
		::RegCloseKey(regKeyLangs.Detach());
	}

	g_fRestartInterface = false;

	AddPage(&m_pageAbout);
	AddPage(&m_pageFirstLaunch);
	AddPage(&m_pageOptions);
	AddPage(&m_pageFiles);
	AddPage(&m_pageAction);
	AddPage(&m_pageProgress);

	SetWizardMode();
}
BOOL ComPortDiscovery::RegQueryValueString(ATL::CRegKey& key, LPCTSTR lpValueName, LPTSTR& pszValue)
{
	//Initialize the output parameter
	pszValue = NULL;

	//First query for the size of the registry value 
	ULONG nChars = 0;
	LSTATUS nStatus = key.QueryStringValue(lpValueName, NULL, &nChars);
	if (nStatus != ERROR_SUCCESS)
	{
		SetLastError(nStatus);
		return FALSE;
	}

	//Allocate enough bytes for the return value
	DWORD dwAllocatedSize = ((nChars + 1) * sizeof(TCHAR)); //+1 is to allow us to NULL terminate the data if required
	pszValue = reinterpret_cast<LPTSTR>(LocalAlloc(LMEM_FIXED, dwAllocatedSize));
	if (pszValue == NULL)
		return FALSE;

	//We will use RegQueryValueEx directly here because ATL::CRegKey::QueryStringValue does not handle non-Null terminated data 
	DWORD dwType = 0;
	ULONG nBytes = dwAllocatedSize;
	pszValue[0] = _T('\0');
	nStatus = RegQueryValueEx(key, lpValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pszValue), &nBytes);
	if (nStatus != ERROR_SUCCESS)
	{
		LocalFree(pszValue);
		pszValue = NULL;
		SetLastError(nStatus);
		return FALSE;
	}
	if ((dwType != REG_SZ) && (dwType != REG_EXPAND_SZ))
	{
		LocalFree(pszValue);
		pszValue = NULL;
		SetLastError(ERROR_INVALID_DATA);
		return FALSE;
	}
	if ((nBytes % sizeof(TCHAR)) != 0)
	{
		LocalFree(pszValue);
		pszValue = NULL;
		SetLastError(ERROR_INVALID_DATA);
		return FALSE;
	}
	if (pszValue[(nBytes / sizeof(TCHAR)) - 1] != _T('\0'))
	{
		//Forcibly NULL terminate the data ourselves
		pszValue[(nBytes / sizeof(TCHAR))] = _T('\0');
	}

	return TRUE;
}
bool CCustomPropSheet::GetFontSubstitute(LPCTSTR pszRegvName, CString& strDest)
{
	ATL::CRegKey regKeyFontSubst;
	regKeyFontSubst.Create(HKEY_LOCAL_MACHINE, SZ_REGK_FONT_SUBSTITUTES);
	int nError = ERROR_SUCCESS;
	TCHAR szMsShellDlg[LF_FACESIZE] = { 0 };
	ULONG cchMaxLen = _countof(szMsShellDlg);
	nError = regKeyFontSubst.QueryStringValue(pszRegvName, szMsShellDlg, &cchMaxLen);
	if (nError == ERROR_SUCCESS)
	{
		strDest = szMsShellDlg;
		return (true);
	}
	else
	{
		return (false);
	}
}
Exemple #6
0
RegData AddinHelper::QueryRegVal(HKEY hkey, LPCTSTR lpszKeyName, LPCTSTR lpszValuename, REGSAM flag)
{
	ATL::CRegKey key;
	HRESULT hr;
	RegData rd;
	if ((hr = key.Open(hkey, lpszKeyName, flag)) == ERROR_SUCCESS) {
		TCHAR tszValue[MAX_PATH] = {0};
		ULONG lLen = MAX_PATH;
		DWORD dwInfo;
		if (key.QueryStringValue(lpszValuename, tszValue, &lLen) == ERROR_SUCCESS){
			std::wstring wstrInfo =  tszValue;
			rd.strData = wstrInfo;
		}
		else if((key.QueryDWORDValue(lpszValuename, dwInfo) == ERROR_SUCCESS)){
			rd.dwData = dwInfo;
		}
		
		key.Close();
	}
	return rd;
}
bool IsPDFPrinterInstalled(std::tstring& stReason)
{
   const _bstr_t c_sAmynuProgId = _T("CDIntfEx.CDIntfEx");
   try
   {
      CLSID clsid = {0};
      HRESULT hr = CLSIDFromProgID(c_sAmynuProgId, &clsid);
      if (S_OK != hr)
         throw Workshare::Com::ComException(_T("PDF converter not installed."), hr);

      ATL::CRegKey printerRegistry;
      const TCHAR c_sRegistryKey[] = _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\Devices\0");
      LONG lResult = printerRegistry.Open(HKEY_CURRENT_USER, c_sRegistryKey, KEY_READ);
      if(ERROR_SUCCESS != lResult)
      {
         CStdString sMessage;
         sMessage.Format(_T("Failed to open the key \"%s\" for reading the configured PDF printer"), c_sRegistryKey);
         throw Workshare::System::SystemException(_T("Failed to open the registry to read the configured PDF printer"), lResult);
      }

      TCHAR szData[MAX_PATH];
      ULONG ulSize(sizeof(szData)/sizeof(szData[0]));
      lResult = printerRegistry.QueryStringValue(c_sPDFDriverName, szData, &ulSize);
      if(ERROR_SUCCESS != lResult)
      {
         CStdString sMessage;
         sMessage.Format(_T("The PDF converter is not correctly installed. The printer \"%s\" needs to be installed. Rerun the installation of the PDF printer."), c_sPDFDriverName);
         throw Workshare::System::SystemException(sMessage.c_str(), lResult);
      }	
   }
   catch(const Workshare::Exception& e) 
   { 
      stReason = e.Message;
      return false;
   }
   catch(...) { unexpected(); }
   return true;
}