Beispiel #1
0
bool RegistryHelper::writeValue(const LPTSTR valueName, std::wstring const& value) const
{
    ATL::CRegKey regKey;

    return
        (ERROR_SUCCESS == regKey.Open(key_, keyName_, KEY_WRITE) ||
         ERROR_SUCCESS == regKey.Create(key_, keyName_, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE)) &&
        ERROR_SUCCESS == regKey.SetStringValue(valueName, value.c_str());
}
Beispiel #2
0
static HRESULT RegisterClassRoot(const std::wstring& clsid, const std::wstring& dllPath)
{
	ATL::CRegKey key;
	std::wstring inprocServerKey = L"CLSID\\" + clsid + L"\\InprocServer32";
	LSTATUS lStatus = key.Create(HKEY_CLASSES_ROOT, inprocServerKey.c_str());
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	lStatus = key.SetStringValue(NULL, dllPath.c_str());
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	lStatus = key.SetStringValue(L"ThreadingModel", L"Apartment");
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	key.Close();
	return S_OK;
}
Beispiel #3
0
static HRESULT RegisterCopyHook(const std::wstring& clsid)
{
	ATL::CRegKey key;
	std::wstring copyHookKey = L"Directory\\shellex\\CopyHookHandlers\\";
	copyHookKey += L"AYBSharing";
	LSTATUS lStatus = key.Create(HKEY_CLASSES_ROOT, copyHookKey.c_str());
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	lStatus = key.SetStringValue(NULL, clsid.c_str());
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	key.Close();
	return S_OK;
}
Beispiel #4
0
static HRESULT RegisterIconOverlay(const std::wstring& clsid)
{
	ATL::CRegKey key;
	std::wstring iconOverlayKey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers\\";
	iconOverlayKey += L" DeskUpdateRemind";
	LSTATUS lStatus = key.Create(HKEY_LOCAL_MACHINE, iconOverlayKey.c_str());
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	lStatus = key.SetStringValue(NULL, clsid.c_str());
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	key.Close();
	return S_OK;
}
Beispiel #5
0
static HRESULT RegisterBho(const std::wstring& clsid)
{
	ATL::CRegKey key;
	std::wstring bhoKey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects\\";
	bhoKey += clsid;
	LSTATUS lStatus = key.Create(HKEY_LOCAL_MACHINE, bhoKey.c_str());
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	lStatus = key.SetStringValue(NULL, L"YBBHO");
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	lStatus = key.SetDWORDValue(L"NoExplorer",1);
	if (lStatus != ERROR_SUCCESS) {
		return HRESULT_FROM_WIN32(lStatus);
	}
	key.Close();
	return S_OK;
}
Beispiel #6
0
void CMainWizard::OnLanguageChange(UINT uMenuID)
{
	CUpdateItApp* pApp = DYNAMIC_DOWNCAST(CUpdateItApp, AfxGetApp());
	ASSERT_VALID(pApp);

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

	int nError = ERROR_SUCCESS;

	if (static_cast<HKEY>(regKeyLangs) != NULL)
	{
		UINT iLangName = uMenuID - ((ID_LANGUAGE_ENGLISH & 0x00F0) >> 4);
		nError = regKeyLangs.SetStringValue(SZ_REGV_LANGUAGES_CURRENT, m_arrLangNames[iLangName]);
		if (nError == ERROR_SUCCESS)
		{
			CheckLangMenuItem(iLangName);
			regKeyLangs.Flush();
			g_fRestartInterface = true;
			PostMessage(PSM_PRESSBUTTON, PSBTN_CANCEL, 0);
		}
		::RegCloseKey(regKeyLangs.Detach());
	}
void CCliOptionsForm::AssociateFileType()
{
	TCHAR strExeLocation[MAX_PATH];
	if (GetModuleFileName(NULL, strExeLocation, MAX_PATH))
	{
		CPath pathExe(strExeLocation);
		pathExe.Canonicalize();

		HKEY hKeyBase = HKEY_CURRENT_USER;
		if (DSUtil::IsUserAdmin())
			hKeyBase = HKEY_LOCAL_MACHINE;

		// extension
		ATL::CRegKey regKey;
		CString strReg = _T("Software\\Classes\\.grfx");
		if (ERROR_SUCCESS != regKey.Create(hKeyBase, strReg))
		{
			DSUtil::ShowError(_T("Can't register file extension"));
			return;
		}
		regKey.SetStringValue(NULL, _T("GraphStudioNext.GraphFile.v1"));
		regKey.Close();

		// FileType description
		strReg = _T("Software\\Classes\\GraphStudioNext.GraphFile.v1");
		if (ERROR_SUCCESS != regKey.Create(hKeyBase, strReg))
		{
			DSUtil::ShowError(_T("Can't register filetype"));
			return;
		}
		regKey.SetStringValue(NULL, _T("GraphStudioNext Filter Graph File"));
		regKey.Close();

		// Open command
		strReg = _T("Software\\Classes\\GraphStudioNext.GraphFile.v1\\shell\\open\\command");
		if (ERROR_SUCCESS != regKey.Create(hKeyBase, strReg))
		{
			DSUtil::ShowError(_T("Can't register filetype open command"));
			return;
		}
		CString strOpen = pathExe;
		strOpen.Append(_T(" \"%1\""));
		regKey.SetStringValue(NULL, strOpen);
		regKey.Close();


		// Register Icon for the filetype
		strReg = _T("Software\\Classes\\GraphStudioNext.GraphFile.v1\\DefaultIcon");
		if (ERROR_SUCCESS != regKey.Create(hKeyBase, strReg))
		{
			DSUtil::ShowError(_T("Can't set the icon for the filetype"));
			return;
		}
		CString strIcon = pathExe;
		strIcon.Append(_T(",-129"));
		regKey.SetStringValue(NULL, strIcon);

		// Reload Shell with the new Icon
		SHChangeNotify(SHCNE_ASSOCCHANGED,NULL,NULL,NULL);

		DSUtil::ShowInfo(_T("FileType .grfx successfully registered."));
	}
}
BOOL CNTEventLogSource::Install(LPCTSTR lpszLogName, LPCTSTR lpszSourceName, LPCTSTR lpszEventMessageFile, LPCTSTR pszEventCategoryMessageFile, LPCTSTR pszEventParameterMessageFile, DWORD dwTypesSupported, DWORD dwCategoryCount)
{
  //Validate our parameters
  ATLASSUME(lpszLogName != NULL);
  ATLASSERT(_tcslen(lpszLogName));
  ATLASSUME(lpszSourceName != NULL);
  ATLASSERT(_tcslen(lpszSourceName));
  ATLASSUME(lpszEventMessageFile != NULL);

  //What will be the return value from this function, assume the worst
  BOOL bSuccess = FALSE;

  //Make the necessary updates to the registry
  TCHAR szKey[4096];
  _stprintf_s(szKey, sizeof(szKey)/sizeof(TCHAR), _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s"), lpszLogName);
  ATL::CRegKey appKey;
  if (appKey.Create(HKEY_LOCAL_MACHINE, szKey) == ERROR_SUCCESS)
  {
    ATL::CRegKey sourceKey;
    if (sourceKey.Create(appKey, lpszSourceName, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL) == ERROR_SUCCESS)
    {
      //Write the EventMessageFile string value
      bSuccess = sourceKey.SetStringValue(_T("EventMessageFile"), lpszEventMessageFile) == ERROR_SUCCESS;

      //Write the TypesSupported value
      bSuccess = bSuccess && sourceKey.SetDWORDValue(_T("TypesSupported"), dwTypesSupported) == ERROR_SUCCESS;

      //Write the CategoryCount value if required
      if (dwCategoryCount && bSuccess)
        bSuccess = sourceKey.SetDWORDValue(_T("CategoryCount"), dwCategoryCount) == ERROR_SUCCESS;

      //Write the CategoryMessageFile string if required
      if (pszEventCategoryMessageFile && _tcslen(pszEventCategoryMessageFile) && bSuccess)
        bSuccess = sourceKey.SetStringValue(_T("CategoryMessageFile"), pszEventCategoryMessageFile) == ERROR_SUCCESS;

      //Write the ParameterMessageFile string if required
      if (pszEventParameterMessageFile && _tcslen(pszEventParameterMessageFile) && bSuccess)
        bSuccess = sourceKey.SetStringValue(_T("ParameterMessageFile"), pszEventParameterMessageFile) == ERROR_SUCCESS;

      //Update the sources registry key so that the event viewer can filter on the events which we write to the event log
      if (bSuccess)
      {
        CNTServiceStringArray sources;
        if (GetStringArrayFromRegistry(appKey, _T("Sources"), sources))
        {
          //If our name is not in the array then add it
          BOOL bFoundMyself = FALSE;
        #ifdef CNTSERVICE_MFC_EXTENSIONS
          for (int i=0; i<sources.GetSize() && !bFoundMyself; i++)
            bFoundMyself = (sources.GetAt(i) == lpszSourceName);
        #else
          bFoundMyself = (std::find(sources.begin(), sources.end(), lpszSourceName) != sources.end());
        #endif
          if (!bFoundMyself)
          {
          #ifdef CNTSERVICE_MFC_EXTENSIONS
            sources.Add(lpszSourceName);
          #else
            sources.push_back(lpszSourceName);
          #endif
            SetStringArrayIntoRegistry(appKey, _T("Sources"), sources);
          }
        }
      }
    }
  }

  return bSuccess;
}
Beispiel #9
0
HRESULT CreateGreenShieldService(const wchar_t* szDllPath)
{
	TSAUTO();
	SC_HANDLE schSCManager = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if (schSCManager == NULL) {
		DWORD dwOpenError = ::GetLastError();
		TSERROR4CXX("OpenSCManager failed. Error: " << dwOpenError);
		return HRESULT_FROM_WIN32(dwOpenError);
	}

	ScopeResourceHandle<SC_HANDLE, BOOL (WINAPI*)(SC_HANDLE)> autoCloseSCManagerHandle(schSCManager, ::CloseServiceHandle);

	const wchar_t* szImagePath = L"%SystemRoot%\\System32\\svchost.exe -k ADCleanService";

	SC_HANDLE schService = ::CreateService(
		schSCManager,
        szServiceName,
        szServiceName,
        SERVICE_ALL_ACCESS,
        SERVICE_WIN32_SHARE_PROCESS,
        SERVICE_AUTO_START,
        SERVICE_ERROR_NORMAL,
        szImagePath,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL);

	if(schService == NULL) {
		DWORD dwCreateError = ::GetLastError();
		TSERROR4CXX("CreateService failed. Error: " << dwCreateError);
		return HRESULT_FROM_WIN32(dwCreateError);
	}

	ScopeResourceHandle<SC_HANDLE, BOOL (WINAPI*)(SC_HANDLE)> autoCloseServiceHandle(schService, ::CloseServiceHandle);
	SERVICE_DESCRIPTION description = { L"广告清道夫实时过滤服务。" };
	ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &description);

	// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\ADCleanService
	ATL::CRegKey key;
	LONG lRegResult = key.Open(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\services\\ADCleanService", KEY_READ);
	if(lRegResult != ERROR_SUCCESS) {
		TSERROR4CXX("Filed to open reg key. Key: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\ADCleanService. Error: " << lRegResult);
		return HRESULT_FROM_WIN32(lRegResult);
	}

	key.Close();

	// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\ADCleanService\Parameters
	lRegResult = key.Create(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\services\\ADCleanService\\Parameters");
	if(lRegResult != ERROR_SUCCESS) {
		TSERROR4CXX("Failed to create reg key. Key: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\ADCleanService\\Parameters. Error: " << lRegResult);
		return HRESULT_FROM_WIN32(lRegResult);
	}
	lRegResult = key.SetStringValue(L"ServiceDll", szDllPath, REG_EXPAND_SZ);
	if(lRegResult != ERROR_SUCCESS) {
		TSERROR4CXX("Failed to set reg value. Key: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\ADCleanService\\Parameters\\ServiceDll. Error: " << lRegResult);
		return HRESULT_FROM_WIN32(lRegResult);
	}
	key.Close();

	// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost
	lRegResult = key.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost");
	if(lRegResult != ERROR_SUCCESS) {
		TSERROR4CXX("Failed to open reg key. Key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost. Error: " << lRegResult);
		return HRESULT_FROM_WIN32(lRegResult);
	}
	lRegResult = key.SetMultiStringValue(L"ADCleanService", L"ADCleanService\0");
	if(lRegResult != ERROR_SUCCESS) {
		TSERROR4CXX("Failed to set reg value. Key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost\\ADCleanService. Error: " << lRegResult);
		return HRESULT_FROM_WIN32(lRegResult);
	}

	// start service
	::StartService(schService, 0, NULL);
	return S_OK;
}