/*********************************************************************** * regsvr_key_defvalueA */ static LONG register_key_defvalueA( HKEY base, WCHAR const *name, char const *value) { LONG res; HKEY key; res = RegCreateKeyExW(base, name, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &key, NULL); if (res != ERROR_SUCCESS) return res; res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value, lstrlenA(value) + 1); RegCloseKey(key); return res; }
static void myspace_links_register() { HKEY hkey; char szBuf[MAX_PATH], szExe[MAX_PATH * 2], szShort[MAX_PATH]; GetModuleFileNameA(hInst, szBuf, sizeof(szBuf)); GetShortPathNameA(szBuf, szShort, sizeof(szShort)); //LOG(LOG_DEBUG, "Links: register"); if (RegCreateKeyA(HKEY_CLASSES_ROOT, "myim", &hkey) == ERROR_SUCCESS) { RegSetValueA(hkey, NULL, REG_SZ, "URL:MySpace IM Protocol", strlen("URL:MySpace IM Protocol")); RegSetValueExA(hkey, "URL Protocol", 0, REG_SZ, (PBYTE) "", 1); RegCloseKey(hkey); } else { //LOG(LOG_ERROR, "Links: register - unable to create registry key (root)"); return; } if (RegCreateKeyA(HKEY_CLASSES_ROOT, "myim\\DefaultIcon", &hkey) == ERROR_SUCCESS) { char szIcon[MAX_PATH]; mir_snprintf(szIcon, sizeof(szIcon), "%s,0", szShort); RegSetValueA(hkey, NULL, REG_SZ, szIcon, strlen(szIcon)); RegCloseKey(hkey); } else { //LOG(LOG_ERROR, "Links: register - unable to create registry key (DefaultIcon)"); return; } if (RegCreateKeyA(HKEY_CLASSES_ROOT, "myim\\shell\\open\\command", &hkey) == ERROR_SUCCESS) { // MSVC exports differently than gcc/mingw #ifdef _MSC_VER mir_snprintf(szExe, sizeof(szExe), "RUNDLL32.EXE %s,_myspace_links_exec@16 %%1", szShort); //LOG(LOG_INFO, "Links: registering (%s)", szExe); #else mir_snprintf(szExe, sizeof(szExe), "RUNDLL32.EXE %s,myspace_links_exec@16 %%1", szShort); //LOG(LOG_INFO, "Links: registering (%s)", szExe); #endif RegSetValueA(hkey, NULL, REG_SZ, szExe, strlen(szExe)); RegCloseKey(hkey); } else { //LOG(LOG_ERROR, "Links: register - unable to create registry key (command)"); return; } }
int CGlobalSettings::SetGlobalValue(const char *product, const char *key, const char *value, int ival) { HKEY hKey,hSubKey; DWORD dwLen; cvs::string regkey; if(!isAdmin()) return -1; if(!product || !strcmp(product,"cvsnt")) regkey="Software\\CVS"; else cvs::sprintf(regkey,64,"Software\\March Hare Software Ltd\\%s",product); if(RegOpenKeyExA(HKEY_LOCAL_MACHINE,regkey.c_str(),0,KEY_READ|KEY_WRITE,&hKey) && RegCreateKeyExA(HKEY_LOCAL_MACHINE,regkey.c_str(),0,NULL,0,KEY_READ|KEY_WRITE,NULL,&hKey,NULL)) { return -1; // Couldn't open or create key } if(key) { if(RegOpenKeyExA(hKey,key,0,KEY_WRITE,&hSubKey) && RegCreateKeyExA(hKey,key,0,NULL,0,KEY_WRITE,NULL,&hSubKey,NULL)) { RegCloseKey(hKey); return -1; // Couldn't open or create key } RegCloseKey(hKey); hKey=hSubKey; } DWORD dw = (DWORD)ival,err; dwLen=(DWORD)sizeof(DWORD); err = RegSetValueExA(hKey,value,0,REG_DWORD,(LPBYTE)&dw,dwLen); if(err) { dw = GetLastError(); RegCloseKey(hKey); return -1; } RegCloseKey(hKey); return 0; }
string HomeDirPlugin::getConfig() { if (!m_bSave) return ""; HKEY subKey; DWORD disposition; if (RegCreateKeyExA(HKEY_CURRENT_USER, key_name, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &subKey, &disposition) != ERROR_SUCCESS) return ""; if (!m_bDefault){ RegSetValueExA(subKey, path_value, 0, REG_SZ, (const unsigned char*)m_homeDir.c_str(), m_homeDir.length()); }else{ RegDeleteValueA(subKey, path_value); } RegCloseKey(subKey); return ""; }
/*********************************************************************** * regsvr_progid */ static LONG register_progid( WCHAR const *clsid, char const *progid, char const *curver_progid, char const *name, char const *extra) { LONG res; HKEY progid_key; res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &progid_key, NULL); if (res != ERROR_SUCCESS) return res; if (name) { res = RegSetValueExA(progid_key, NULL, 0, REG_SZ, (CONST BYTE*)name, strlen(name) + 1); if (res != ERROR_SUCCESS) goto error_close_progid_key; } if (clsid) { res = register_key_defvalueW(progid_key, clsid_keyname, clsid); if (res != ERROR_SUCCESS) goto error_close_progid_key; } if (curver_progid) { res = register_key_defvalueA(progid_key, curver_keyname, curver_progid); if (res != ERROR_SUCCESS) goto error_close_progid_key; } if (extra) { HKEY extra_key; res = RegCreateKeyExA(progid_key, extra, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &extra_key, NULL); if (res == ERROR_SUCCESS) RegCloseKey(extra_key); } error_close_progid_key: RegCloseKey(progid_key); return res; }
/***************************************************************************************************\ * Функа ChangeRegKey; * изменение (добавление) значения параметра реестра (в данной ситуации добавляем своё значение в 'Path'); * Вход: * hKey - дескриптор указанного ключа реестра; * pszSubKey - адрес имени открываемого подключа (раздела реестра) * pszValName - адрес имени параметра (значения); * pszAddVal - адрес строкового значения, которое будет добавлено в уже существующее значение указанного параметра; * Выход: * 1 - если всё прошло успешно, или 0 - если хуйня * Замметки: * по умолчанию в этом модуле изменяется системная переменная окружения 'Path'; * в Win7/etc - это админская привилегия, так что будем аккуратней =)! \***************************************************************************************************/ DWORD ChangeRegKey(HKEY hKey, char *pszSubKey, char *pszValName, char *pszAddVal) { long lRes; HKEY hNewKey; char *pszData; DWORD num = MAX_LEN_BUF; DWORD dwRes = 0; lRes = RegOpenKeyExA(hKey, pszSubKey, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hNewKey); //open the specified reg key; if(lRes != ERROR_SUCCESS) return 0; lRes = RegQueryValueExA(hNewKey, pszValName, 0, 0, 0, &num); //get num_bytes for our buffer; if(lRes != ERROR_SUCCESS) return 0; else { pszData = (char*)malloc(sizeof(char) * num + strlen(pszAddVal) + 1); //alloc lRes = RegQueryValueExA(hNewKey, pszValName, 0, 0, pszData, &num); //get reg key value; if(lRes != ERROR_SUCCESS) { free(pszData); return 0; } } strcat(pszData, pszAddVal); //add new value; lRes = RegSetValueExA(hNewKey, pszValName, 0, REG_EXPAND_SZ, pszData, strlen(pszData) + 1); //update reg key value; free(pszData); if(lRes != ERROR_SUCCESS) return 0; lRes = RegCloseKey(hNewKey); //close reg key; if(lRes != ERROR_SUCCESS) return 0; //tell the system (programs etc) about change (new path); SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, &dwRes); return 1; }
int CGlobalSettings::_SetUserValue(const char *product, const char *key, const char *value, const char *buffer) { HKEY hKey,hSubKey; DWORD dwLen; cvs::string regkey; if(!product || !strcmp(product,"cvsnt")) regkey="Software\\Cvsnt"; else cvs::sprintf(regkey,64,"Software\\March Hare Software Ltd\\%s",product); if(RegOpenKeyExA(HKEY_CURRENT_USER,regkey.c_str(),0,KEY_READ|KEY_WRITE,&hKey) && RegCreateKeyExA(HKEY_CURRENT_USER,regkey.c_str(),0,NULL,0,KEY_READ|KEY_WRITE,NULL,&hKey,NULL)) { return -1; // Couldn't open or create key } if(key) { if(RegOpenKeyExA(hKey,key,0,KEY_WRITE,&hSubKey) && RegCreateKeyExA(hKey,key,0,NULL,0,KEY_WRITE,NULL,&hSubKey,NULL)) { RegCloseKey(hKey); return -1; // Couldn't open or create key } RegCloseKey(hKey); hKey=hSubKey; } if(!buffer) { RegDeleteValueA(hKey,value); } else { dwLen=(DWORD)strlen(buffer); if(RegSetValueExA(hKey,value,0,REG_SZ,(LPBYTE)buffer,dwLen+1)) { RegCloseKey(hKey); return -1; } } RegCloseKey(hKey); return 0; }
static void add_dos_device( const char *udi, const char *device, const char *mount_point, const char *type ) { struct dos_drive *drive; /* first check if it already exists */ LIST_FOR_EACH_ENTRY( drive, &drives_list, struct dos_drive, entry ) { if (!strcmp( udi, drive->udi )) goto found; } if (!(drive = HeapAlloc( GetProcessHeap(), 0, sizeof(*drive) ))) return; if (!(drive->udi = HeapAlloc( GetProcessHeap(), 0, strlen(udi)+1 ))) { HeapFree( GetProcessHeap(), 0, drive ); return; } strcpy( drive->udi, udi ); list_add_tail( &drives_list, &drive->entry ); found: drive->drive = add_drive( device, type ); if (drive->drive != -1) { HKEY hkey; set_mount_point( drive, mount_point ); WINE_TRACE( "added device %c: udi %s for %s on %s type %s\n", 'a' + drive->drive, wine_dbgstr_a(udi), wine_dbgstr_a(device), wine_dbgstr_a(mount_point), wine_dbgstr_a(type) ); /* hack: force the drive type in the registry */ if (!RegCreateKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Drives", &hkey )) { char name[3] = "a:"; name[0] += drive->drive; if (!type || strcmp( type, "cdrom" )) type = "floppy"; /* FIXME: default to floppy */ RegSetValueExA( hkey, name, 0, REG_SZ, (const BYTE *)type, strlen(type) + 1 ); RegCloseKey( hkey ); } send_notify( drive->drive, DBT_DEVICEARRIVAL ); } }
/************************************************************************** * IStream_fnRelease */ static ULONG WINAPI IStream_fnRelease(IStream *iface) { ISHRegStream *This = impl_from_IStream(iface); ULONG refCount = InterlockedDecrement(&This->ref); TRACE("(%p)->(ref before=%u)\n",This, refCount + 1); if (!refCount) { TRACE(" destroying SHReg IStream (%p)\n",This); if (This->hKey) { /* write back data in REG_BINARY */ if (This->dwMode == STGM_READWRITE || This->dwMode == STGM_WRITE) { if (This->dwLength) { if (This->bUnicode) RegSetValueExW(This->hKey, This->u.keyNameW, 0, REG_BINARY, (const BYTE *) This->pbBuffer, This->dwLength); else RegSetValueExA(This->hKey, This->u.keyNameA, 0, REG_BINARY, (const BYTE *) This->pbBuffer, This->dwLength); } else { if (This->bUnicode) RegDeleteValueW(This->hKey, This->u.keyNameW); else RegDeleteValueA(This->hKey, This->u.keyNameA); } } RegCloseKey(This->hKey); } HeapFree(GetProcessHeap(),0,This->u.keyNameA); HeapFree(GetProcessHeap(),0,This->pbBuffer); HeapFree(GetProcessHeap(),0,This); return 0; } return refCount; }
//----- (004649EF) -------------------------------------------------------- int __fastcall ReadWindowsRegistryInt(const char *pKey, int uDefValue) { DWORD cbData; // [sp+8h] [bp-20h]@1 LPCSTR lpValueName; // [sp+Ch] [bp-1Ch]@1 DWORD dwDisposition; // [sp+10h] [bp-18h]@2 BYTE Data[4]; // [sp+14h] [bp-14h]@5 HKEY hKey; // [sp+18h] [bp-10h]@1 HKEY phkResult; // [sp+1Ch] [bp-Ch]@1 HKEY v10; // [sp+20h] [bp-8h]@1 HKEY v11; // [sp+24h] [bp-4h]@1 lpValueName = pKey; v11 = 0; v10 = 0; hKey = 0; phkResult = 0; cbData = 4; if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hKey) )// for 64 bit { if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) ) { if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v10, &dwDisposition) ) { if ( !RegCreateKeyExA(v10, "1.0", 0, "", 0, 0xF003Fu, 0, &v11, &dwDisposition) ) { LSTATUS status; if ( status = RegQueryValueExA(v11, lpValueName, 0, 0, Data, &cbData) ) { status; GetLastError(); *(int *)Data = uDefValue; RegSetValueExA(v11, lpValueName, 0, 4u, Data, 4u); } RegCloseKey(v11); } RegCloseKey(v10); } RegCloseKey(phkResult); } RegCloseKey(hKey); } return *(int *)Data; }
bool Win32Registry::getString( const char *section, const char *field, const char *descriptive_field, const char *default_val, char *buf, int buf_size ) { DWORD size = buf_size; DWORD type; { // read user key if ( RegQueryValueExA( m_user_key, field, 0, &type, (LPBYTE)buf, &size ) != ERROR_SUCCESS || type != REG_SZ ) { // didnt work. Try read machine key if ( RegQueryValueExA( m_machine_key, field, 0, &type, (LPBYTE)buf, &size ) != ERROR_SUCCESS || type != REG_SZ ) { // still didnt work. write default to machine key // and return default. strncpy_s( buf, buf_size, default_val, buf_size - 1 ); buf[buf_size - 1] = 0; RegSetValueExA( m_machine_key, field, 0, REG_SZ, (LPBYTE)buf, strlen( buf ) + 1 ); return false; } } } return true; }
void setLucidRegValue(const CString csSectionPath, const CString csKey, CString csValue) { HKEY myKey; DWORD varType = REG_SZ; //the value's a REG_SZ type DWORD buffSize = 1024; DWORD dwDisp; char pBuf[1024] = {'\0'}; const int nLen = csValue.GetLength(); strcpy(pBuf, csValue.GetBuffer(nLen)); // if the Section Path doesn't exist then create it if (RegOpenKeyEx(HKEY_CURRENT_USER,csSectionPath, 0, KEY_WRITE, &myKey)) { RegCreateKeyEx(HKEY_CURRENT_USER, csSectionPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &myKey, &dwDisp); } RegSetValueExA(myKey,csKey,0,varType,(const BYTE *)pBuf,sizeof(pBuf)); RegCloseKey(myKey); csValue.ReleaseBuffer(); }
void InitNodeId(Skype_Inst *pInst) { DWORD BufSz = sizeof(pInst->NodeID); HKEY hKey; if (QueryRegValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\FakeSkype\\NodeId", (LPBYTE)&pInst->NodeID, &BufSz)) return; *(int64_t *)&pInst->NodeID = BytesRandomI64(); if (RegCreateKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\FakeSkype", &hKey) == ERROR_SUCCESS) { RegSetValueExA(hKey, "NodeId", 0, REG_BINARY, (LPBYTE)&pInst->NodeID, sizeof(pInst->NodeID)); RegCloseKey(hKey); } //FIXED NODEID //memcpy_s(NodeID, NODEID_SZ, "\x49\x63\xff\xee\xe0\x5c\x9d\xf8", NODEID_SZ); //memcpy_s(NodeID, NODEID_SZ, "\x97\xca\xb1\x72\x06\xf6\x72\xb4", NODEID_SZ); }
//------------------------------------------------------------------------------- void CLogWindow::Save() { char szFileName[MAX_PATH]; DWORD dwTemp = MAX_PATH; if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LogDestination",NULL,NULL, (BYTE*)szFileName,&dwTemp)) { // Key was not found. Use C: strcpy(szFileName,""); } else { // need to remove the file name char* sz = strrchr(szFileName,'\\'); if (!sz) sz = strrchr(szFileName,'/'); if (sz) *sz = 0; } OPENFILENAME sFilename1 = { sizeof(OPENFILENAME), g_hDlg,GetModuleHandle(NULL), "Log files\0*.txt", NULL, 0, 1, szFileName, MAX_PATH, NULL, 0, NULL, "Save log to file", OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR, 0, 1, ".txt", 0, NULL, NULL }; if(GetSaveFileName(&sFilename1) == 0) return; // Now store the file in the registry RegSetValueExA(g_hRegistry,"LogDestination",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH); FILE* pFile = fopen(szFileName,"wt"); fprintf(pFile,this->szPlainText.c_str()); fclose(pFile); CLogDisplay::Instance().AddEntry("[INFO] The log file has been saved", D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0)); }
/************************************************************************** * WNetCachePassword [MPR.@] Saves password in cache * * NOTES * Only the parameter count is verified * * ---- everything below this line might be wrong (js) ----- * RETURNS * Success: WN_SUCCESS * Failure: WN_ACCESS_DENIED, WN_BAD_PASSWORD, WN_BADVALUE, WN_NET_ERROR, * WN_NOT_SUPPORTED, WN_OUT_OF_MEMORY */ DWORD WINAPI WNetCachePassword( LPSTR pbResource, /* [in] Name of workgroup, computer, or resource */ WORD cbResource, /* [in] Size of name */ LPSTR pbPassword, /* [in] Buffer containing password */ WORD cbPassword, /* [in] Size of password */ BYTE nType, /* [in] Type of password to cache */ WORD x) { HKEY hkey; DWORD r; LPSTR valname; WARN( "(%p(%s), %d, %p(%s), %d, %d, 0x%08x): totally insecure\n", pbResource, debugstr_a(pbResource), cbResource, pbPassword, debugstr_a(pbPassword), cbPassword, nType, x ); /* @@ Wine registry key: HKCU\Software\Wine\Wine\Mpr */ r = RegCreateKeyA( HKEY_CURRENT_USER, mpr_key, &hkey ); if( r ) return WN_ACCESS_DENIED; valname = MPR_GetValueName( pbResource, cbResource, nType ); if( valname ) { r = RegSetValueExA( hkey, valname, 0, REG_BINARY, (LPBYTE)pbPassword, cbPassword ); if( r ) r = WN_CANCEL; else r = WN_SUCCESS; HeapFree( GetProcessHeap(), 0, valname ); } else r = WN_OUT_OF_MEMORY; RegCloseKey( hkey ); return r; }
long Win32Registry::getInt( const char *section, const char *field, const char *descriptive_field, long default_val ) { DWORD val = default_val; DWORD size = sizeof( val ); DWORD type; { // try read user setting if ( RegQueryValueExA( m_user_key, field, 0, &type, (LPBYTE)&val, &size ) != ERROR_SUCCESS || type != REG_DWORD ) { // didnt work... try read machine key if ( RegQueryValueExA( m_machine_key, field, 0, &type, (LPBYTE)&val, &size ) != ERROR_SUCCESS || type != REG_DWORD ) { // still didnt work. Use default // and write default to machine key RegSetValueExA( m_machine_key, field, 0, REG_DWORD, (LPBYTE)&val, sizeof( val ) ); } } } return val; }
void WinWindow::doRunOnStart() { std::string runPath = "\"" + getExecutablePath() + "\" -m"; Helper::request_privileges(SE_TAKE_OWNERSHIP_NAME); HKEY hKey; LONG result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_WRITE, &hKey); if (result == ERROR_SUCCESS) { if ((result = RegSetValueExA( hKey, "NOSA-Server", 0, REG_SZ, (BYTE*)runPath.c_str(), runPath.length())) == ERROR_SUCCESS) MessageBox(NULL, "Now NOSA-Server service will launch of computer start.", "Done!", MB_ICONINFORMATION | MB_OK); else MessageBox(NULL, "You don't have sufficient rights to edit your registry. Please try run this application with admin privilege.", "Error!", MB_ICONERROR | MB_OK); } else MessageBox(NULL, "Your registry has wrong format!", "Error!", MB_ICONERROR | MB_OK); RegCloseKey(hKey); return; }
static void test_machine_guid(void) { char originalGuid[40]; LONG r; HKEY key; DWORD size; HCRYPTPROV hCryptProv; BOOL restoreGuid = FALSE, ret; r = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography", 0, KEY_ALL_ACCESS, &key); if (r != ERROR_SUCCESS) { skip("couldn't open HKLM\\Software\\Microsoft\\Cryptography\n"); return; } /* Cache existing MachineGuid, and delete it */ size = sizeof(originalGuid); r = RegQueryValueExA(key, "MachineGuid", NULL, NULL, (BYTE *)originalGuid, &size); if (r == ERROR_SUCCESS) { restoreGuid = TRUE; r = RegDeleteValueA(key, "MachineGuid"); ok(!r, "RegDeleteValueA failed: %d\n", r); } else ok(r == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", r); /* Create and release a provider */ ret = pCryptAcquireContextA(&hCryptProv, szKeySet, NULL, PROV_RSA_FULL, 0); ok(ret || broken(!ret && GetLastError() == NTE_KEYSET_ENTRY_BAD /* NT4 */), "CryptAcquireContextA failed: %08x\n", GetLastError()); pCryptReleaseContext(hCryptProv, 0); if (restoreGuid) RegSetValueExA(key, "MachineGuid", 0, REG_SZ, (const BYTE *)originalGuid, strlen(originalGuid)+1); RegCloseKey(key); }
int CGlobalSettings::SetUserValue(const char *product, const char *key, const char *value, int ival) { HKEY hKey,hSubKey; DWORD dwLen; cvs::string regkey; if(!product || !strcmp(product,"cvsnt")) regkey="Software\\Cvsnt"; else cvs::sprintf(regkey,64,"Software\\March Hare Software Ltd\\%s",product); if(RegOpenKeyExA(HKEY_CURRENT_USER,regkey.c_str(),0,KEY_READ|KEY_WRITE,&hKey) && RegCreateKeyExA(HKEY_CURRENT_USER,regkey.c_str(),0,NULL,0,KEY_READ|KEY_WRITE,NULL,&hKey,NULL)) { return -1; // Couldn't open or create key } if(key) { if(RegOpenKeyExA(hKey,key,0,KEY_WRITE,&hSubKey) && RegCreateKeyExA(hKey,key,0,NULL,0,KEY_WRITE,NULL,&hSubKey,NULL)) { RegCloseKey(hKey); return -1; // Couldn't open or create key } RegCloseKey(hKey); hKey=hSubKey; } DWORD dw = ival; dwLen=(DWORD)sizeof(DWORD); if(RegSetValueExA(hKey,value,0,REG_DWORD,(LPBYTE)&dw,dwLen)) { RegCloseKey(hKey); return -1; } RegCloseKey(hKey); return 0; }
bool QSettingsPrivate::sysWriteEntry( const QString &key, int data ) { #ifdef QT_CHECK_STATE if ( key.isNull() || key.isEmpty() ) { qWarning( "QSettingsPrivate::sysWriteEntry: invalid null/empty key." ); return false; } #endif // QT_CHECK_STATE long ret = -1; QString value; HKEY hkey = sysd->createKey( key, KEY_SET_VALUE , value , globalScope ); if ( hkey ) { ret = QT_WA_INLINE( RegSetValueExW( hkey, ( LPCTSTR ) value.ucs2(), 0, REG_DWORD, ( LPBYTE ) & data, sizeof( int ) ), RegSetValueExA( hkey, ( LPCSTR ) value.latin1(), 0, REG_DWORD, ( LPBYTE ) & data, sizeof( int ) ) ); RegCloseKey( hkey ); } return ( ret == ERROR_SUCCESS ); }
/* static public */ BOOL REGUTIL::SetRegValue( const char *szKeyName, const char *szKeyword, const char *szValue ) { HKEY hKey; // handle to the new reg key. // create the registration key. if ( RegCreateKeyExA( HKEY_CLASSES_ROOT, szKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS ) { // set the value (if there is one). if ( szValue != NULL ) { RegSetValueExA( hKey, szKeyword, 0, REG_SZ, (BYTE *)szValue, ((strlen( szValue ) + 1) * sizeof ( char )) ); } RegCloseKey( hKey ); return TRUE; } return FALSE; } // REGUTIL::SetRegValue
ENGINE_API BOOL REG_SetString(const CTString &strKey, const CTString &strString) { // parse the key name HKEY hKeyRoot; CTString strKeyPath; CTString strKeyName; ParseKeyName(strKey, hKeyRoot, strKeyPath, strKeyName); // create the registry key HKEY hkey; DWORD dwDisposition; LONG lRes = RegCreateKeyExA(hKeyRoot, (const char*)strKeyPath, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisposition); if (lRes!=ERROR_SUCCESS) { return FALSE; } // set the value lRes = RegSetValueExA(hkey, strKeyName, 0, REG_SZ, (const UBYTE*)(const char*)strString, strlen(strString)); // close the key RegCloseKey(hkey); return lRes==ERROR_SUCCESS; }
static void save_sys_colors (HKEY baseKey) { char colorStr[13]; HKEY hKey; int i; if (RegCreateKeyExW( baseKey, strColorKey, 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0 ) == ERROR_SUCCESS) { for (i = 0; i < NUM_SYS_COLORS; i++) { COLORREF col = GetSysColor (i); sprintf (colorStr, "%d %d %d", GetRValue (col), GetGValue (col), GetBValue (col)); RegSetValueExA (hKey, SysColorsNames[i], 0, REG_SZ, (BYTE*)colorStr, strlen (colorStr)+1); } RegCloseKey (hKey); } }
void CController::ReplaceResource() { char szCurDir[256], szRunBlock[256], szNewRunBlock[256], szBlockWindows[256], szNewBlockWindows[256]; char szSysDir[256]; GetModuleFileName(NULL, szCurDir, 256); char* ptemp = strrchr(szCurDir, '\\'); *ptemp = 0; GetSystemDirectory(szSysDir, 256); sprintf(szRunBlock, "%s\\RunBlock.exe", szCurDir); sprintf(szNewRunBlock, "%s\\RunBlock.exe", szSysDir); sprintf(szBlockWindows, "%s\\BlockWindows.exe", szCurDir); sprintf(szNewBlockWindows, "%s\\BlockWindows.exe", szSysDir); CopyFile(szRunBlock, szNewRunBlock, FALSE); CopyFile(szBlockWindows, szNewBlockWindows, FALSE); ShellExecute(NULL, "open", szNewRunBlock, NULL, NULL, SW_SHOW); HKEY hKey; RegOpenKeyA(HKEY_LOCAL_MACHINE, LPCSTR("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), &hKey); RegSetValueExA(hKey, LPCSTR("BlockWindows"), 0, REG_SZ, (const unsigned char*)(szNewRunBlock), strlen(szNewRunBlock)); RegCloseKey(hKey); }
LONG winfrip_confstore_RegSetValueEx(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData) { WINFRIPP_CONFSTORE_DEBUG_ASSERT(hKey); WINFRIPP_CONFSTORE_DEBUG_ASSERT(lpValueName); WINFRIPP_CONFSTORE_DEBUG_ASSERT(lpData); WINFRIPP_CONFSTORE_DEBUG_ASSERT(cbData > 0); /* * XXX document */ switch (winfrip_confstore_backend_get()) { default: WINFRIPP_CONFSTORE_DEBUG_FAIL(); return ERROR_INVALID_FUNCTION; case WINFRIP_GENERAL_STORE_BACKEND_REGISTRY: return RegSetValueExA(hKey, lpValueName, Reserved, dwType, lpData, cbData); case WINFRIP_GENERAL_STORE_BACKEND_EPHEMERAL: case WINFRIP_GENERAL_STORE_BACKEND_FILE: /* TODO implement */ return ERROR_INVALID_FUNCTION; } }
//----- (00464B02) -------------------------------------------------------- void __fastcall WriteWindowsRegistryString(const char *pKey, const char *pString) { size_t v2; // eax@5 const char *lpValueName; // [sp+4h] [bp-1Ch]@1 const char *Str; // [sp+8h] [bp-18h]@1 DWORD dwDisposition; // [sp+Ch] [bp-14h]@2 HKEY hKey; // [sp+10h] [bp-10h]@1 HKEY phkResult; // [sp+14h] [bp-Ch]@1 HKEY v8; // [sp+18h] [bp-8h]@1 HKEY v9; // [sp+1Ch] [bp-4h]@1 Str = pString; lpValueName = pKey; v9 = 0; v8 = 0; hKey = 0; phkResult = 0; if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey) ) { if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) ) { if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v8, &dwDisposition) ) { if ( !RegCreateKeyExA(v8, "1.0", 0, "", 0, 0xF003Fu, 0, &v9, &dwDisposition) ) { v2 = strlen(Str); RegSetValueExA(v9, lpValueName, 0, 1u, (const BYTE *)Str, v2 + 1); RegCloseKey(v9); } RegCloseKey(v8); } RegCloseKey(phkResult); } RegCloseKey(hKey); } }
static unsigned dbg_save_internal_vars(void) { HKEY hkey; int i; /* @@ Wine registry key: HKCU\Software\Wine\WineDbg */ if (RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &hkey)) { WINE_ERR("Cannot create WineDbg key in registry\n"); return FALSE; } for (i = 0; i < DBG_IV_LAST; i++) { /* FIXME: type should be inferred from basic type -if any- of intvar */ if (dbg_internal_vars[i].pval == &dbg_internal_vars[i].val) { DWORD val = dbg_internal_vars[i].val; RegSetValueExA(hkey, dbg_internal_vars[i].name, 0, REG_DWORD, (BYTE *)&val, sizeof(val)); } } RegCloseKey(hkey); return TRUE; }
bool RegistryUtil::writeString(const std::string& key, const std::string& value, const std::string& data) { size_t pos = key.find('\\', 0); if (pos == std::string::npos) { return false; } HKEY hkey = getRootKeyFromString(key.c_str(), pos); if (hkey == NULL) { return false; } HKEY openKey; int32 result = RegOpenKeyExA(hkey, (key.c_str() + pos + 1), 0, KEY_WRITE, &openKey); ASSERT(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); if (result == ERROR_SUCCESS) { result = RegSetValueExA(openKey, value.c_str(), 0, REG_SZ, reinterpret_cast<const BYTE*>(data.c_str()), ((int)data.size() + 1)); ASSERT(result == ERROR_SUCCESS); RegCloseKey(openKey); } return (result == ERROR_SUCCESS); }
/* * Removing the path from the %PATH% environment in the registry on Win-NT's */ int svn_removent (char cPathSvn[255]) { long lRet; char cPathTmp[BUFSIZE]; HKEY hKey; char cKey[BUFSIZE], cPathNew[BUFSIZE], cPathCur[BUFSIZE]; DWORD dwBufLen, lpType; char *pcPathCur[BUFSIZE]; char * pcSubPath; *pcPathCur=cPathCur; dwBufLen=BUFSIZE; lstrcpy (cPathTmp, cPathSvn); if (! svn_svnpath_exists(cPathTmp)) { exit (1); } lstrcpy(cKey, "SYSTEM\\CurrentControlSet\\"); lstrcat(cKey, "Control\\Session Manager\\Environment"); /* Get value, value type and current path from HKLM and try to append * the svnpath to it */ lRet = svn_read_regval(HKEY_LOCAL_MACHINE, "Path", cKey, &*pcPathCur, &lpType); /* Reopen the key for writing */ lRet = RegCreateKeyEx( HKEY_LOCAL_MACHINE, cKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwBufLen); /* Remove the Subversion path from the system path and put the new path * on cPathNew*/ pcSubPath = strtok (cPathCur,";"); strcpy(cPathNew, ""); while (pcSubPath != NULL) { if (strcmp(pcSubPath, cPathSvn)) { if (strlen(cPathNew)==0) { lstrcpy(cPathNew, pcSubPath); } else { lstrcat(cPathNew, ";"); lstrcat(cPathNew, pcSubPath); } } pcSubPath = strtok (NULL, ";"); } lRet = RegSetValueExA(hKey, "Path", 0, lpType, (BYTE*)cPathNew, strlen(cPathNew)+1); RegCloseKey(hKey); /* If it went wrong to do it with HKLM, then try HKCU */ if (lRet != 0) { strcpy(cPathCur, ""); lRet = svn_read_regval(HKEY_CURRENT_USER, "Path", "Environment", &*pcPathCur, &lpType); pcSubPath = strtok (cPathCur,";"); strcpy(cPathNew, ""); while (pcSubPath != NULL) { if (strcmp(pcSubPath, cPathSvn)) { if (strlen(cPathNew)==0) { lstrcpy(cPathNew, pcSubPath); } else { lstrcat(cPathNew, ";"); lstrcat(cPathNew, pcSubPath); } } pcSubPath = strtok (NULL, ";"); } /* Reopen the key for writing */ lRet = RegCreateKeyEx( HKEY_CURRENT_USER, "Environment", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwBufLen); lRet = RegSetValueExA(hKey, "Path", 0, lpType, (LPBYTE)cPathNew, strlen(cPathNew)+1); if (lRet != 0) { return (1); } RegCloseKey(hKey); } if (lRet != 0) { return (lRet); } else { /* Tell the system about the new path */ SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) "Environment", SMTO_ABORTIFHUNG, 5000, &lRet); } return (0); }
/*********************************************************************** * register_coclasses */ static HRESULT register_coclasses(struct regsvr_coclass const *list) { LONG res = ERROR_SUCCESS; HKEY coclass_key; res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL); if (res != ERROR_SUCCESS) goto error_return; for (; res == ERROR_SUCCESS && list->clsid; ++list) { WCHAR buf[39]; HKEY clsid_key; StringFromGUID2(list->clsid, buf, 39); res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL); if (res != ERROR_SUCCESS) goto error_close_coclass_key; if (list->name) { res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ, (CONST BYTE*)(list->name), strlen(list->name) + 1); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } if (list->ips) { res = register_key_defvalueA(clsid_key, ips_keyname, list->ips); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } if (list->ips32) { HKEY ips32_key; res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &ips32_key, NULL); if (res != ERROR_SUCCESS) goto error_close_clsid_key; res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ, (CONST BYTE*)list->ips32, lstrlenA(list->ips32) + 1); if (res == ERROR_SUCCESS && list->ips32_tmodel) res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ, (CONST BYTE*)list->ips32_tmodel, strlen(list->ips32_tmodel) + 1); RegCloseKey(ips32_key); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } if (list->progid) { res = register_key_defvalueA(clsid_key, progid_keyname, list->progid); if (res != ERROR_SUCCESS) goto error_close_clsid_key; res = register_progid(buf, list->progid, NULL, list->name, list->progid_extra); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } if (list->viprogid) { res = register_key_defvalueA(clsid_key, viprogid_keyname, list->viprogid); if (res != ERROR_SUCCESS) goto error_close_clsid_key; res = register_progid(buf, list->viprogid, list->progid, list->name, list->progid_extra); if (res != ERROR_SUCCESS) goto error_close_clsid_key; } error_close_clsid_key: RegCloseKey(clsid_key); } error_close_coclass_key: RegCloseKey(coclass_key); error_return: return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; }