STDMETHODIMP C[!output Safe_root]PropPage::Apply(void) { WCHAR wszStr[MAXSTRING] = { 0 }; double fScaleFactor = 1.0; GetDlgItemText(IDC_SCALEFACTOR, wszStr, sizeof(wszStr) / sizeof(wszStr[0])); swscanf_s(wszStr, L"%lf", &fScaleFactor); // make sure scale factor is valid if ((fScaleFactor < 0.0) || (fScaleFactor > 1.0)) { if (::LoadString(_Module.GetResourceInstance(), IDS_SCALERANGEERROR, wszStr, sizeof(wszStr) / sizeof(wszStr[0]))) { MessageBox(wszStr); } return E_FAIL; } // update the registry CRegKey key; LONG lResult; lResult = key.Create(HKEY_CURRENT_USER, kwszPrefsRegKey); if (ERROR_SUCCESS == lResult) { [!if VSNET] DWORD dwValue = (DWORD) (fScaleFactor * 65536); lResult = key.SetValue(kwszPrefsScaleFactor, REG_DWORD, &dwValue, sizeof(dwValue)); [!else] lResult = key.SetValue((DWORD) (fScaleFactor * 65536), kwszPrefsScaleFactor ); [!endif] }
void CMruStorage::WriteList() { ASSERT(!m_strSection.IsEmpty()); ASSERT(!m_strEntryFormat.IsEmpty()); LPTSTR pszEntry = new TCHAR[m_strEntryFormat.GetLength() + 5]; CString strHKeyString = k_strStoreHere; strHKeyString += "\\"; strHKeyString += m_strSection; CRegKey aKey; DWORD dwNew = 0; if (ERROR_SUCCESS == aKey.Create(HKEY_CURRENT_USER, strHKeyString, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &dwNew)) { if (dwNew == REG_CREATED_NEW_KEY) { // Let's save the DLG name as well to make it easier to recognize this // id when browsing the registry. aKey.SetValue(HKEY_CURRENT_USER, strHKeyString, m_strParentWindowName); } POSITION pos = m_lstStrings.GetHeadPosition(); for (int iMRU = 1; pos && iMRU <= m_nSize; iMRU++) { wsprintf(pszEntry, m_strEntryFormat, iMRU); if (!m_lstStrings.GetAt(pos).IsEmpty()) { VERIFY(ERROR_SUCCESS == aKey.SetValue(HKEY_CURRENT_USER, strHKeyString, m_lstStrings.GetAt(pos), pszEntry)); } m_lstStrings.GetNext(pos); } } else { ASSERT(0); // Should never fail. } delete [] pszEntry; }
STDAPI DllRegisterServerRaw(BOOL bForce) { if(!bForce){// Может мы уже зарегены? CRegKey reg; LONG lRet=0; CRegKey key2; if(key2.Open(HKEY_CURRENT_USER, SAVE_REGKEY)==ERROR_SUCCESS && key2.m_hKey!=NULL){ DWORD hookData=0; DWORD lSize = sizeof(hookData),dwType=0; RegQueryValueEx(key2.m_hKey,"ShellExtRegistered",NULL, &dwType,(LPBYTE)(&hookData), &lSize); if(hookData!=0){ plgOptions.bRegistered=1; } } } // Не смотря ни на что даже при наличии регистрации в эксплорер меню может быть не видно!!! :( // поэтому всеже регим каждый раз /*if(plgOptions.bRegistered){ return 0; }*/ CoInitializeEx(0,COINIT_APARTMENTTHREADED); // If we're on NT, add ourselves to the list of approved shell extensions. // Note that you should *NEVER* use the overload of CRegKey::SetValue with // 4 parameters. It lets you set a value in one call, without having to // call CRegKey::Open() first. However, that version of SetValue() has a // bug in that it requests KEY_ALL_ACCESS to the key. That will fail if the // user is not an administrator. (The code should request KEY_WRITE, which // is all that's necessary.) if ( 0 == (GetVersion() & 0x80000000UL) ){ CRegKey reg; LONG lRet=0; lRet = reg.Open ( HKEY_LOCAL_MACHINE,_T("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"),KEY_SET_VALUE); if ( ERROR_SUCCESS == lRet ){ lRet = reg.SetValue ( _T("WKShellExtender class"), _T("{AC95BA2C-8211-45D4-AB5C-C2A9BCCC8FB6}") ); } } // registers object, typelib and all interfaces in typelib BOOL bRes=_Module.RegisterServer(FALSE); if(bRes==0){ if(!plgOptions.bRegistered){// Запоминаем сами... CRegKey key2; if(key2.Open(HKEY_CURRENT_USER, SAVE_REGKEY)!=ERROR_SUCCESS){ key2.Create(HKEY_CURRENT_USER, SAVE_REGKEY); } if(key2.m_hKey!=NULL){ DWORD hookData=1; RegSetValueEx(key2.m_hKey,"ShellExtRegistered",0,REG_DWORD,(BYTE*)(&hookData),sizeof(hookData)); } } InterlockedIncrement(&plgOptions.bRegistered); } CoUninitialize(); return bRes; }
BOOL SetRegistryValue(HKEY hRoot, LPCTSTR wcSubKey, LPCTSTR wcName, LPBYTE pValue, DWORD dwSize, DWORD dwType) { DWORD result = ERROR_INVALID_DATA; CRegKey reg; result = reg.Create(hRoot, wcSubKey); if(result == ERROR_SUCCESS) result = reg.SetValue(wcName, dwType, pValue, dwSize); return (result == ERROR_SUCCESS); }
STDMETHODIMP C[!output Safe_root]PropPage::Apply(void) { // update the registry CRegKey key; LONG lResult; lResult = key.Create(HKEY_CURRENT_USER, kwszPrefsRegKey); if (ERROR_SUCCESS == lResult) { [!if VSNET] DWORD dwValue = (DWORD) m_Color; lResult = key.SetValue(kwszPrefsTextColor, REG_DWORD, &dwValue, sizeof(dwValue)); [!else] lResult = key.SetValue((DWORD) m_Color, kwszPrefsTextColor ); [!endif] }
//*************************************** //* Date : 5.26.99 //* Last Modified : 1.20.2000 //* Function name : DllRegisterServer //* Description : //*************************************** // STDAPI DllRegisterServer(void) { _TCHAR strCLSID[50]; OLECHAR strWideCLSID[50]; CRegKey key; HRESULT hr; USES_CONVERSION; hr = _Module.RegisterServer(TRUE); if (SUCCEEDED(hr)) { if (::StringFromGUID2(CLSID_CopyPathContextMenu, strWideCLSID, 50) > 0) { _tcscpy(strCLSID, OLE2CT(strWideCLSID)); hr = key.SetValue(HKEY_CLASSES_ROOT, _T("*\\shellex\\ContextMenuHandlers\\CopyPathExt\\"), strCLSID); hr = key.SetValue(HKEY_CLASSES_ROOT, _T("directory\\shellex\\ContextMenuHandlers\\CopyPathExt\\"), strCLSID); hr = key.SetValue(HKEY_CLASSES_ROOT, _T("drive\\shellex\\ContextMenuHandlers\\CopyPathExt\\"), strCLSID); } } return hr; }
BOOL CDlg_Options_Downloads_Flv::Apply() { CRegKey keyIeLow; if (ERROR_SUCCESS != keyIeLow.Open (HKEY_CURRENT_USER, _T ("Software\\Microsoft\\Internet Explorer\\LowRegistry\\Software\\FreeDownloadManager.ORG\\Free Download Manager\\Settings\\FlvMonitoring"), KEY_ALL_ACCESS)) { keyIeLow.Create (HKEY_CURRENT_USER, _T ("Software\\Microsoft\\Internet Explorer\\LowRegistry\\Software\\FreeDownloadManager.ORG\\Free Download Manager\\Settings\\FlvMonitoring"), NULL, 0, KEY_ALL_ACCESS, NULL, NULL); } BOOL bShowBtn = IsDlgButtonChecked (IDC_SHOWGETITBTN) == BST_CHECKED; _App.FlvMonitoring_ShowDownloadItButton (bShowBtn); keyIeLow.SetValue (bShowBtn, _T ("ShowDownloadItBtn")); bool bEnable = IsDlgButtonChecked (IDC_ENABLE_MONITORING) == BST_CHECKED; _App.FlvMonitoring_Enable (bEnable); keyIeLow.SetValue (bEnable, _T ("Enable")); DWORD dwFSDI = 0; if (bEnable) { DWORD dw = 0; if (IsDlgButtonChecked (IDC_M_IE) == BST_CHECKED) dw |= FSDI_PROCESS_IE; if (IsDlgButtonChecked (IDC_M_FIREFOX) == BST_CHECKED) dw |= FSDI_PROCESS_FIREFOX; if (IsDlgButtonChecked (IDC_M_OPERA) == BST_CHECKED) dw |= FSDI_PROCESS_OPERA; if (IsDlgButtonChecked (IDC_M_NETSCAPE) == BST_CHECKED) dw |= FSDI_PROCESS_NETSCAPE; if (IsDlgButtonChecked (IDC_M_SAFARI) == BST_CHECKED) dw |= FSDI_PROCESS_SAFARI; if (IsDlgButtonChecked (IDC_M_CHROME) == BST_CHECKED) dw |= FSDI_PROCESS_CHROME; if (IsDlgButtonChecked (IDC_M_SEAMONKEY) == BST_CHECKED) dw |= FSDI_PROCESS_SEAMONKEY; dwFSDI = dw; _App.FlvMonitoring_ProcessList (dw); keyIeLow.SetValue (dw, _T ("ProcessList")); std::vector <tstring> v; getFsdiProcessList (dw, v); vmsFlvSniffInjector::o ().setProcessList (v); } vmsFlvSniffInjector::o ().Enable (bEnable); if (dwFSDI != m_dwOldFSDI) { if (dwFSDI != m_dwInitialFSDI) setBrowserRestartRequired (true); m_dwOldFSDI = dwFSDI; } return TRUE; }
void CConfigSet::WriteVariablesToRegistry (const char *reg_name, const char *config_section) { LONG result; char buff[1024]; CRegKey newrk; snprintf(buff, sizeof(buff), "%s\\\\%s", reg_name, config_section); result = newrk.Create(HKEY_CURRENT_USER, buff); if (result != ERROR_SUCCESS) return; for (config_index_t ix = 0; ix < m_numVariables; ix++) { switch (m_variables[ix].m_type) { case CONFIG_TYPE_INTEGER: newrk.SetValue(m_variables[ix].m_value.m_ivalue, m_variables[ix].m_sName); break; case CONFIG_TYPE_BOOL: newrk.SetValue(m_variables[ix].m_value.m_bvalue ? 1 : 0, m_variables[ix].m_sName); break; case CONFIG_TYPE_STRING: newrk.SetValue(ToAscii(&m_variables[ix]), m_variables[ix].m_sName); break; case CONFIG_TYPE_FLOAT: newrk.SetValue(ToAscii(&m_variables[ix]), m_variables[ix].m_sName); break; } } newrk.Close(); }
bool vmsIeHelper::RegisterExeAsSafeToDragDrop(LPCTSTR ptszAppGuid) { CString strKey = _T ("Software\\Microsoft\\Internet Explorer\\Low Rights\\DragDrop\\"); strKey += ptszAppGuid; CRegKey key; bool bOK = ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, strKey, KEY_ALL_ACCESS); if (!bOK) bOK = ERROR_SUCCESS == key.Create (HKEY_LOCAL_MACHINE, strKey, NULL, 0, KEY_ALL_ACCESS, NULL, NULL); if (!bOK) bOK = ERROR_SUCCESS == key.Open (HKEY_CURRENT_USER, strKey, KEY_ALL_ACCESS); if (!bOK) bOK = ERROR_SUCCESS == key.Create (HKEY_CURRENT_USER, strKey, NULL, 0, KEY_ALL_ACCESS, NULL, NULL); if (!bOK) return false; TCHAR tsz [MY_MAX_PATH] = _T (""); GetModuleFileName (NULL, tsz, MY_MAX_PATH); LPTSTR ptsz = strrchr (tsz, '\\'); if (!ptsz) return false; CString strName = ptsz+1; *ptsz = 0; bOK = ERROR_SUCCESS == key.SetValue (strName, _T ("AppName")); bOK = ERROR_SUCCESS == key.SetValue (tsz, _T ("AppPath")) && bOK; bOK = ERROR_SUCCESS == key.SetValue (3, _T ("Policy")) && bOK; return bOK; }
extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpCmdLine*/, int nShowCmd) { TCHAR szSvrName[1024] = { 0 }; TCHAR szRegKey[1024] = { 0 }; LoadString(NULL, IDS_SERVICENAME,szSvrName, 1024); _stprintf(szRegKey, L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Minimal\\%s",szSvrName); CRegKey DocKey; if (DocKey.Open(HKEY_LOCAL_MACHINE,szRegKey) != ERROR_SUCCESS) { DocKey.Create(HKEY_LOCAL_MACHINE,szRegKey); } DocKey.SetValue(_T("Service"), NULL); DocKey.Close(); memset((char*)szRegKey, 0, sizeof(szRegKey)); _stprintf(szRegKey, L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Network\\%s", szSvrName); if (DocKey.Open(HKEY_LOCAL_MACHINE,szRegKey) != ERROR_SUCCESS) { DocKey.Create(HKEY_LOCAL_MACHINE,szRegKey); } DocKey.SetValue(_T("Service"), NULL); DocKey.Close(); return _AtlModule.WinMain(nShowCmd); }
void CPagePlayers::SaveSendChatMRUToRegistry() { // Open/create the registry key CRegKey key; if (ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, HKLM_AllSrvUI)) return; // SendChatMRU CRegKey keyMRU; if (ERROR_SUCCESS != keyMRU.Create(key, TEXT("SendChatMRU"))) return; // Write the count of strings int cStrings = min(m_comboSendChat.GetCount(), c_cMaxChatsInRegistry); // mdvalley: SetDWORDValue (swap) keyMRU.SetValue(cStrings, TEXT(".Count")); // Write each string for (int i = 0; i < cStrings; ++i) { TCHAR szInt[16]; CString strMRUItem; m_comboSendChat.GetLBText(i, strMRUItem); // mdvalley: SetStringValue(swap) keyMRU.SetValue(strMRUItem, _itot(i, szInt, 10)); } }
void CUpdateMyself::UpdateSecService() { USES_CONVERSION; CRegKey key; if (key.Open(HKEY_LOCAL_MACHINE, L"Software\\HTLUpdate", KEY_READ|KEY_WRITE|KEY_WOW64_32KEY) == ERROR_SUCCESS) { key.SetValue((DWORD)1, L"HTUSecService"); } CString strUpdatePath = m_strProgramPath + L"\\HTUpdate"; CString strCommand; strCommand.Empty(); strCommand.Format(L"%s\\%s -unregserver", strUpdatePath, L"HTLUpdateSecService.exe"); WinExec(T2A(strCommand), SW_HIDE); Sleep(1000); CString strTempFile = strUpdatePath + L"\\HTLUpdateSecService.exe.tmp"; while (PathFileExists(strTempFile)) { if (DeleteFile(strTempFile)) { break; } SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (hSCM != NULL) { SC_HANDLE hService = ::OpenService(hSCM, L"HTLUpdateSecService", SERVICE_QUERY_STATUS); if (hService != NULL) { SERVICE_STATUS status; ::QueryServiceStatus( hService, &status); if (status.dwCurrentState == SERVICE_RUNNING) { CString strCommand = L"sc stop HTLUpdateSecService"; WinExec(T2A(strCommand), SW_HIDE); } } ::CloseServiceHandle(hService); ::CloseServiceHandle(hSCM); } Sleep(1000); } strCommand = L""; strCommand.Format(L"%s\\%s -service", strUpdatePath, L"HTLUpdateSecService.exe"); OutputDebugString(strCommand); WinExec(T2A(strCommand), SW_HIDE); strCommand = L""; strCommand.Format(L"sc start HTLUpdateSecService"); OutputDebugString(strCommand); WinExec(T2A(strCommand), SW_HIDE); key.SetValue((DWORD)0, L"HTUSecService"); key.Close(); }
void CPBXClientApp::IntegrateIntoOutlook() { CRegKey regKey; DWORD value; // Check if Outlook is installed when OutCALL runs for the first time, and if so // write the appropriate registry keys if (regKey.Open(HKEY_CURRENT_USER, APP_REG_KEY)==ERROR_SUCCESS) { if (regKey.QueryValue(value, _T("TryOutlookIntegration"))!=ERROR_SUCCESS) { regKey.SetValue((DWORD)0, _T("TryOutlookIntegration")); regKey.Close(); TCHAR path[256]; //WIN32_FIND_DATA FindFileData; //HANDLE hFind; SHGetFolderPath(NULL,CSIDL_LOCAL_APPDATA,NULL,0,path); // //hFind = FindFirstFile(CString(path) + "\\Microsoft\\Outlook\\outlook.pst", &FindFileData); //if (hFind == INVALID_HANDLE_VALUE) { // AfxGetApp()->WriteProfileInt("Settings", "OutlookFeatures", 0); // return; // outlook is not installed //} else { // FindClose(hFind); //} if (regKey.Open(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Office\\Outlook"))!=ERROR_SUCCESS) { ::theApp.WriteProfileInt("Settings", "OutlookFeatures", 0); return; // outlook is not installed } else { regKey.Close(); } try { CFile::Remove(CString(path) + "\\Microsoft\\Outlook\\extend.dat"); //this will refresh outlook cache for plugins (addins) } catch (...) { } CString addinPath = GetInstallDir() + "\\" + CString(APP_NAME) + ".dll"; CString szAddinValue = "4.0;" + addinPath + ";1;11111111111111;1111111"; if (regKey.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Exchange\\Client\\Extensions"))==0) { regKey.SetValue(szAddinValue, CString(APP_NAME)); regKey.Close(); } ::theApp.WriteProfileInt("Settings", "OutlookFeatures", 1); } else { regKey.Close(); } } }
STDAPI DllRegisterServer(void) { // On NT, add ourself to the list of approved shell extensions. if ( 0 == (GetVersion() & 0x80000000) ) { CRegKey reg; LONG lRet; lRet = reg.Open ( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"), KEY_SET_VALUE ); if ( ERROR_SUCCESS != lRet ) return E_ACCESSDENIED; lRet = reg.SetValue ( _T("Hard Links Shell Extension"), _T("{3C06DFAE-062F-11D4-8D3B-919D46C1CE19}") ); if ( ERROR_SUCCESS != lRet ) return E_ACCESSDENIED; } // registers object, typelib and all interfaces in typelib return _Module.RegisterServer(TRUE); }
HRESULT CPigEngine::put_AccountServer(BSTR bstrServer) { // Get the number of pigs that exist XLock lock(this); long cPigs = 0; if (m_pPigs) RETURN_FAILED(m_pPigs->get_Count(&cPigs)); // Fail if there are any pigs in existance if (cPigs) return AtlReportError(CLSID_PigSession, IDS_E_PROPUT_PIGSEXIST, IID_IPigSession, 0, _Module.GetResourceInstance()); // Open the registry key of the AppID CRegKey key; RETURN_FAILED(_Module.OpenAppIDRegKey(key)); // Save the specified value USES_CONVERSION; long lr = key.SetValue(BSTRLen(bstrServer) ? OLE2CT(bstrServer) : TEXT(""), TEXT("AccountServer")); if (ERROR_SUCCESS != lr) return HRESULT_FROM_WIN32(lr); // Save the string m_bstrAccountServer = bstrServer; // Indicate success return S_OK; }
HRESULT TCUserAccount::SetRunAsInteractiveUser(LPCTSTR szAppID) { // Not supported under Windows9x if (IsWin9x()) return S_FALSE; // Copy the specified AppID string to a non-const wide string USES_CONVERSION; UINT cchAppID = max(_tcslen(szAppID), 48) + 1; LPWSTR pszAppID = (LPWSTR)_alloca(cchAppID * sizeof(WCHAR)); wcscpy(pszAppID, T2CW(szAppID)); // Resolve the specified string to an AppID HKEY hkey = NULL; RETURN_FAILED(ResolveAppID(pszAppID, &hkey)); CRegKey key; key.Attach(hkey); // Set "Interactive User" as the RunAs user for the AppID // mdvalley: it used to be SetStringValue, but that ain't in my ATL. LONG lr = key.SetValue(TEXT("RunAs"), TEXT("Interactive User")); if (lr) return HRESULT_FROM_WIN32(lr); // Indicate success return S_OK; }
void CPagePlayers::SavePlayerListColumnOrderToRegistry() { // Open/create the registry key CRegKey key; key.Create(HKEY_LOCAL_MACHINE, HKLM_AllSrvUI); // Get the current column ordering int vecOrder[c_cColumns]; for (int iCol = 0; iCol < c_cColumns; ++iCol) vecOrder[iCol] = iCol; m_listPlayers.GetColumnOrderArray(vecOrder, c_cColumns); // Format a comma-delimited string of the column ordering CString strColumnOrder; for (int i = 0; i < c_cColumns; ++i) { if (i) strColumnOrder += ","; TCHAR szNum[16]; strColumnOrder += _itot(vecOrder[i], szNum, 10); } // Save to the registry // mdvalley: SetStringValue (swap) key.SetValue(strColumnOrder, TEXT("PlayerListColumnOrder")); }
STDAPI DllRegisterServer(void) { // On NT, add our extension to the list of approved extensions. if ( 0 == (GetVersion() & 0x80000000) ) { CRegKey reg; LONG lRet; lRet = reg.Open ( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"), KEY_SET_VALUE ); if ( ERROR_SUCCESS != lRet ) return E_ACCESSDENIED; lRet = reg.SetValue ( _T("MP3 ID3v1 viewer column ext"), _T("{AC146E80-3679-4BCA-9BE4-E36512573E6C}") ); reg.Close(); if ( ERROR_SUCCESS != lRet ) return E_ACCESSDENIED; } // registers object, typelib and all interfaces in typelib return _Module.RegisterServer(TRUE); }
BOOL PASCAL CRegKey::SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName) { CRegKey key; if (!key.Create(hKeyParent, lpszKeyName)) return FALSE; return key.SetValue(lpszValue, lpszValueName); }
HRESULT CPigEngine::put_LobbyMode(PigLobbyMode eMode) { // Get the number of pigs that exist XLock lock(this); long cPigs = 0; if (m_pPigs) RETURN_FAILED(m_pPigs->get_Count(&cPigs)); // Fail if there are any pigs in existance if (cPigs) return AtlReportError(CLSID_PigSession, IDS_E_PROPUT_PIGSEXIST, IID_IPigSession, 0, _Module.GetResourceInstance()); // Fail if an invalid mode is specified if (PigLobbyMode_Club > eMode || eMode > PigLobbyMode_Free) return AtlReportError(CLSID_PigSession, IDS_E_LOBBYMODE_UNSUPPORTED, IID_IPigSession, 0, _Module.GetResourceInstance()); // Open the registry key of the AppID CRegKey key; RETURN_FAILED(_Module.OpenAppIDRegKey(key)); // Save the specified lobby mode to the registry long lr = key.SetValue(static_cast<DWORD>(eMode), TEXT("LobbyMode")); if (ERROR_SUCCESS != lr) return HRESULT_FROM_WIN32(lr); // Save the specified lobby mode m_eLobbyMode = eMode; // Indicate success return S_OK; }
BOOL CRegKey::SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName) { CRegKey key; if (!key.Create(m_hKey, lpszKeyName)) return FALSE; return key.SetValue(lpszValue, lpszValueName); }
static void PASCAL AtlRegisterProgID(LPCTSTR lpszCLSID, LPCTSTR lpszProgID, LPCTSTR lpszUserDesc) { CRegKey keyProgID; keyProgID.Create(HKEY_CLASSES_ROOT, lpszProgID); keyProgID.SetValue(lpszUserDesc); keyProgID.SetKeyValue(szCLSID, lpszCLSID); }
bool ProfileDlg::SetAutoCheckProfile(bool autoStart) { CString str = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"); CRegKey regKey; if(regKey.Open(HKEY_CURRENT_USER, str, KEY_SET_VALUE) == ERROR_SUCCESS) { if(autoStart) { //get the path of our program CString name = AfxGetApp()->m_pszExeName; name +=_T(".exe"); HMODULE hmod = GetModuleHandle(name); CString path; DWORD pathLen = ::GetModuleFileName( hmod, path.GetBufferSetLength(MAX_PATH+1), MAX_PATH); path.ReleaseBuffer( pathLen ); regKey.SetValue(path + _T(" /check"), _T("xp-AntiSpy Profile Check")); } else regKey.DeleteValue(_T("xp-AntiSpy Profile Check")); regKey.Close(); return true; } return false; }
void ProfileDlg::CreateProfile(CString name, SettingVec settings) { CRegKey tmp; if(tmp.Open(HKEY_CURRENT_USER, REGISTRY_LOC, KEY_READ) != ERROR_SUCCESS) { tmp.Create(HKEY_CURRENT_USER, REGISTRY_LOC, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE); } tmp.Close(); if(tmp.Open(HKEY_CURRENT_USER, PROFILES_LOC, KEY_READ) != ERROR_SUCCESS) { tmp.Create(HKEY_CURRENT_USER, PROFILES_LOC, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE); } tmp.Close(); CString profileName = PROFILES_LOC + CString(_T("\\")) + name; CRegKey regKey; if(regKey.Create(HKEY_CURRENT_USER,profileName, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE)== ERROR_SUCCESS) { for(int i=0; i<settings.size(); ++i) { CString name; name.Format(_T("%d"), settings[i].settingID); regKey.SetValue((settings[i].checked)?1:0, name); } regKey.Close(); } UpdateProfilesCombo(); }
LRESULT EditorCommandDialog::onCommand(WORD wNotifyCode, WORD wID, HWND hwndCtrl) { switch (wID) { case IDC_EXE_BROWSE: { char filename[MAX_PATH]; OPENFILENAME ofn; Init_OPENFILENAME(&ofn); filename[0] = '\0'; ofn.hwndOwner = m_hWnd; ofn.lpstrFilter = "Program to edit {*.exe}\0*.exe\0\0"; ofn.lpstrFile = filename; ofn.lpstrDefExt = "exe"; ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; if (GetOpenFileName(&ofn)) SendMessage(GetDlgItem(m_hWnd, IDC_EXECMD_FORMAT), WM_SETTEXT, 0, (LPARAM)filename); } break; case IDOK: { int len = SendMessage(GetDlgItem(m_hWnd, IDC_EXECMD_FORMAT), WM_GETTEXTLENGTH, 0, 0) + 1; char *pszFmt = new char[len]; if (pszFmt) { if (!GetDlgItemText(m_hWnd, IDC_EXECMD_FORMAT, pszFmt, len)) _RPT1(_CRT_WARN, "Cannot get format\r\n", len); else { _RPT1(_CRT_WARN, "format=%s\r\n", pszFmt); CRegKey regEditCmd; if (regEditCmd.Create(HKEY_CURRENT_USER, REGKEY_BASE) == ERROR_SUCCESS) { regEditCmd.SetValue(pszFmt, REGKEY_EDITCMD); regEditCmd.Close(); } else _RPT0(_CRT_ASSERT, "Cannot create registy key\r\n"); } delete[] pszFmt; } } case IDCANCEL: EndDialog(m_hWnd, 0); return TRUE; } return FALSE; }
BOOL CCpuUsage::EnablePerformaceCounters(BOOL bEnable) { if (GetPlatform() != WIN2K_XP) return TRUE; CRegKey regKey; if (regKey.Open(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\PerfOS\\Performance") != ERROR_SUCCESS) return FALSE; regKey.SetValue(!bEnable, "Disable Performance Counters"); regKey.Close(); if (regKey.Open(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\PerfProc\\Performance") != ERROR_SUCCESS) return FALSE; regKey.SetValue(!bEnable, "Disable Performance Counters"); regKey.Close(); return TRUE; }
BOOL CCpuUsage::EnablePerformaceCounters(BOOL bEnable) { if (m_nPlatform!= WIN2K_XP) return TRUE; CRegKey regKey; if (regKey.OpenKey(HKLM, "SYSTEM\\CurrentControlSet\\Services\\PerfOS\\Performance",CRegKey::defWrite) != ERROR_SUCCESS) return FALSE; regKey.SetValue("Disable Performance Counters",(DWORD)!bEnable); regKey.CloseKey(); if (regKey.OpenKey(HKLM, "SYSTEM\\CurrentControlSet\\Services\\PerfProc\\Performance",CRegKey::defWrite) != ERROR_SUCCESS) return FALSE; regKey.SetValue("Disable Performance Counters",(DWORD)!bEnable); regKey.CloseKey(); return TRUE; }
inline HRESULT CServiceModule::RegisterServer(BOOL bRegTypeLib, BOOL bService, char * szAccount, char * szPassword) { HRESULT hr = CoInitialize(NULL); if (FAILED(hr)) return hr; // Remove any previous service since it may point to // the incorrect file Uninstall(); // Add service entries UpdateRegistryFromResource(IDR_Lobby, TRUE); // Adjust the AppID for Local Server or Service CRegKey keyAppID; LONG lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_WRITE); if (lRes != ERROR_SUCCESS) return lRes; CRegKey key; lRes = key.Open(keyAppID, _T("{EFD52202-45CB-454D-B477-33BC5C29BDF1}"), KEY_WRITE); if (lRes != ERROR_SUCCESS) return lRes; key.DeleteValue(_T("LocalService")); if (bService) { // mdvalley: SetStringValue not in my ATL key.SetValue(_T("AllLobby"), _T("LocalService")); key.SetValue(_T("-Service"), _T("ServiceParameters")); // Create service //Install(); InstallService(szAccount, szPassword); } // Add object entries hr = CComModule::RegisterServer(bRegTypeLib); CoUninitialize(); return hr; }
bool CHttpFileDownload::SetWriteRunOnceAndReboot(CString strSource, CString strDest) { bool retval = false; CString strRunOnceFilePath = GetRunOnceFilePath(); if(!strRunOnceFilePath.IsEmpty()) { CRegKey regkey; if(regkey.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", KEY_WRITE) == ERROR_SUCCESS ) { CString strLine; strLine.Format("\"%s\" /cs %s /cd %s", strRunOnceFilePath, strSource, strDest); regkey.SetValue(strLine, "Updater runonce copy"); strLine.Format("\"%s\" /ds %s", strRunOnceFilePath, strSource); regkey.SetValue(strLine, "Updater runonce delete"); regkey.Close(); retval = true; } } return retval; }
void CWTLBrowserView::OnNavigateComplete2(IDispatch* /*pDisp*/, const String& /*szURL*/) { if (!m_savedNavigatingSound.empty()) { CRegKey key; if (key.Open(HKEY_CURRENT_USER, _T("AppEvents\\Schemes\\Apps\\Explorer\\Navigating\\.Current")) == ERROR_SUCCESS) { key.SetValue(m_savedNavigatingSound.c_str()); m_savedNavigatingSound.clear(); } key.Close(); } }