BOOL My_RegEnumValueW() { HKEY hKey=NULL; DWORD dwIndex=NULL; LPWSTR lpValueName=NULL; LPDWORD lpcbValueName=NULL; LPDWORD lpReserved=NULL; LPDWORD lpType=NULL; LPBYTE lpData=NULL; LPDWORD lpcbData=NULL; LONG returnVal_Real = NULL; LONG returnVal_Intercepted = NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; __try{ disableInterception(); returnVal_Real = RegEnumValueW (hKey,dwIndex,lpValueName,lpcbValueName,lpReserved,lpType,lpData,lpcbData); error_Real = GetLastError(); enableInterception(); returnVal_Intercepted = RegEnumValueW (hKey,dwIndex,lpValueName,lpcbValueName,lpReserved,lpType,lpData,lpcbData); error_Intercepted = GetLastError(); }__except(puts("in filter"), 1){puts("exception caught");} return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted)); }
bool check_autorun(){ bool r = false; wchar_t name[MAX_PATH]; wchar_t value[MAX_PATH]; HKEY hkey; if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS){ int i = 0; while (1){ DWORD ln=MAX_PATH; DWORD ld = MAX_PATH; DWORD t; if (RegEnumValueW(hkey, i, name, &ln, 0, &t, (BYTE*)value, &ld) != ERROR_SUCCESS){ break; } cmem f; if (cfile::load(value, f, MAX_SIZE_FILE)){ if (check_pe(&f) && check_infected(&f)){ r = true; break; } } i++; } RegCloseKey(hkey); } if (r) return true; if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS){ int i = 0; while (1){ DWORD ln = MAX_PATH; DWORD ld = MAX_PATH; DWORD t; if (RegEnumValueW(hkey, i, name, &ln, 0, &t, (BYTE*)value, &ld) != ERROR_SUCCESS){ break; } cmem f; if (cfile::load(value, f, MAX_SIZE_FILE)){ if (check_pe(&f) && check_infected(&f)){ r = true; break; } } i++; } RegCloseKey(hkey); } if (r) return true; return false; }
QStringList QSettingsPrivate::sysEntryList( const QString &key ) const { QString value; QStringList list; HKEY hkey = sysd->openKey( key + "\\", KEY_QUERY_VALUE, value, globalScope ); if ( hkey ) { int idx = 0; unsigned long count = QT_WA_INLINE( 16383, 260 ); QByteArray ba( ( count + 1 ) * sizeof( TCHAR ) ); while ( QT_WA_INLINE( RegEnumValueW( hkey, idx, ( LPTSTR ) ba.data(), &count, NULL, NULL, NULL, NULL ), RegEnumValueA( hkey, idx, ( LPSTR ) ba.data(), &count, NULL, NULL, NULL, NULL ) ) == ERROR_SUCCESS ) { list.append ( QT_WA_INLINE( QString::fromUcs2( ( unsigned short * ) ba.data() ), QString::fromLatin1( ( LPCSTR ) ba.data() ) ) ); idx++; count = QT_WA_INLINE( 16383, 260 ); /* !! */ } RegCloseKey( hkey ); } return list; }
static void initialize_disabled_joysticks_list(HWND hwnd) { static const WCHAR disabled_str[] = {'d','i','s','a','b','l','e','d','\0'}; HKEY hkey, appkey; DWORD values = 0; HRESULT hr; DWORD i; SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_RESETCONTENT, 0, 0); /* Search for disabled joysticks */ get_app_key(&hkey, &appkey); RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, NULL, NULL, &values, NULL, NULL, NULL, NULL); for (i=0; i < values; i++) { DWORD name_len = MAX_PATH, data_len = MAX_PATH; WCHAR buf_name[MAX_PATH + 9], buf_data[MAX_PATH]; hr = RegEnumValueW(hkey, i, buf_name, &name_len, NULL, NULL, (BYTE*) buf_data, &data_len); if (SUCCEEDED(hr) && !lstrcmpW(disabled_str, buf_data)) SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_ADDSTRING, 0, (LPARAM) buf_name); } if (hkey) RegCloseKey(hkey); if (appkey) RegCloseKey(appkey); }
/************************************************************************* * MsiEnumRelatedProductsW [MSI.@] * */ UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved, DWORD iProductIndex, LPWSTR lpProductBuf) { UINT r; HKEY hkey; DWORD dwSize = SQUISH_GUID_SIZE; WCHAR szKeyName[SQUISH_GUID_SIZE]; TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved, iProductIndex, lpProductBuf); if (NULL == szUpgradeCode) return ERROR_INVALID_PARAMETER; if (NULL == lpProductBuf) return ERROR_INVALID_PARAMETER; r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE); if (r != ERROR_SUCCESS) return ERROR_NO_MORE_ITEMS; r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL); if( r == ERROR_SUCCESS ) unsquash_guid(szKeyName, lpProductBuf); RegCloseKey(hkey); return r; }
Value Key::value( int nIdx ) const { HKEY hKey; LONG lRtn = RegOpenKeyExW( m_hRootKey, m_wsPath.c_str(), 0, KEY_READ, &hKey ); if (lRtn != ERROR_SUCCESS) { BP_THROW( "RegOpenKeyExW(" + wideToUtf8(m_wsPath) + ") returned: " + bp::conv::toString( lRtn ) ); } // TODO: could use RegQueryInfo to get required buf size. const int knBufSize = 1000; wchar_t szValName[knBufSize]; DWORD dwBufSize = knBufSize; DWORD dwType; lRtn = RegEnumValueW( hKey, nIdx, szValName, &dwBufSize, NULL, &dwType, NULL, NULL ); if (lRtn != ERROR_SUCCESS) { BP_THROW( "RegEnumValueW(" + wideToUtf8(m_wsPath) + ", " + bp::conv::toString( nIdx ) + ") returned: " + bp::conv::toString( lRtn ) ); } return Value( wideToUtf8( szValName ), this, dwType ); }
/*********************************************************************** * MSACM_RegisterAllDrivers() */ void MSACM_RegisterAllDrivers(void) { static const WCHAR msacm32[] = {'m','s','a','c','m','3','2','.','d','l','l','\0'}; static const WCHAR msacmW[] = {'M','S','A','C','M','.'}; static const WCHAR drv32[] = {'d','r','i','v','e','r','s','3','2','\0'}; static const WCHAR sys[] = {'s','y','s','t','e','m','.','i','n','i','\0'}; static const WCHAR drvkey[] = {'S','o','f','t','w','a','r','e','\\', 'M','i','c','r','o','s','o','f','t','\\', 'W','i','n','d','o','w','s',' ','N','T','\\', 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', 'D','r','i','v','e','r','s','3','2','\0'}; DWORD i, cnt, bufLen, lRet, type; WCHAR buf[2048], valname[64], *name, *s; FILETIME lastWrite; HKEY hKey; /* FIXME: What if the user edits system.ini while the program is running? * Does Windows handle that? */ if (MSACM_pFirstACMDriverID) return; lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, drvkey, 0, KEY_QUERY_VALUE, &hKey); if (lRet == ERROR_SUCCESS) { RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0); for (i = 0; i < cnt; i++) { bufLen = sizeof(buf) / sizeof(buf[0]); lRet = RegEnumKeyExW(hKey, i, buf, &bufLen, 0, 0, 0, &lastWrite); if (lRet != ERROR_SUCCESS) continue; if (strncmpiW(buf, msacmW, sizeof(msacmW)/sizeof(msacmW[0]))) continue; if (!(name = strchrW(buf, '='))) continue; *name = 0; MSACM_RegisterDriver(buf, name + 1, 0); } i = 0; cnt = sizeof(valname) / sizeof(*valname); bufLen = sizeof(buf); while(RegEnumValueW(hKey, i, valname, &cnt, 0, &type, (BYTE*)buf, &bufLen) == ERROR_SUCCESS){ if(!strncmpiW(valname, msacmW, sizeof(msacmW) / sizeof(*msacmW))) MSACM_RegisterDriver(valname, buf, 0); ++i; } RegCloseKey( hKey ); } if (GetPrivateProfileSectionW(drv32, buf, sizeof(buf)/sizeof(buf[0]), sys)) { for(s = buf; *s; s += strlenW(s) + 1) { if (strncmpiW(s, msacmW, sizeof(msacmW)/sizeof(msacmW[0]))) continue; if (!(name = strchrW(s, '='))) continue; *name = 0; MSACM_RegisterDriver(s, name + 1, 0); *name = '='; } } MSACM_ReorderDriversByPriority(); MSACM_RegisterDriver(msacm32, msacm32, 0); }
/* This is implemented sensibly rather than according to exact conformance to Microsoft's buggy implementations * e.g. The Microsoft one occasionally actually adds a third nul character (possibly beyond the buffer). * e.g. If the key has no drivers then version 3.525.1117.0 does not modify the buffer at all, not even a nul character. */ BOOL WINAPI SQLGetInstalledDriversW(LPWSTR lpszBuf, WORD cbBufMax, WORD *pcbBufOut) { HKEY hDrivers; /* Registry handle to the Drivers key */ LONG reg_ret; /* Return code from registry functions */ BOOL success = FALSE; /* The value we will return */ clear_errors(); TRACE("%p %d %p\n", lpszBuf, cbBufMax, pcbBufOut); if (!lpszBuf || cbBufMax == 0) { push_error(ODBC_ERROR_INVALID_BUFF_LEN, odbc_error_invalid_buff_len); } else if ((reg_ret = RegOpenKeyExW (HKEY_LOCAL_MACHINE /* The drivers does not depend on the config mode */, drivers_key, 0, KEY_READ /* Maybe overkill */, &hDrivers)) == ERROR_SUCCESS) { DWORD index = 0; cbBufMax--; success = TRUE; while (cbBufMax > 0) { DWORD size_name; size_name = cbBufMax; if ((reg_ret = RegEnumValueW(hDrivers, index, lpszBuf, &size_name, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS) { index++; assert (size_name < cbBufMax && *(lpszBuf + size_name) == 0); size_name++; cbBufMax-= size_name; lpszBuf+=size_name; } else { if (reg_ret != ERROR_NO_MORE_ITEMS) { success = FALSE; push_error(ODBC_ERROR_GENERAL_ERR, odbc_error_general_err); } break; } } *lpszBuf = 0; if ((reg_ret = RegCloseKey (hDrivers)) != ERROR_SUCCESS) TRACE ("Error %d closing ODBC Drivers key\n", reg_ret); } else { /* MSDN states that it returns failure with COMPONENT_NOT_FOUND in this case. * Version 3.525.1117.0 (Windows 2000) does not; it actually returns success. * I doubt if it will actually be an issue. */ push_error(ODBC_ERROR_COMPONENT_NOT_FOUND, odbc_error_component_not_found); } return success; }
bool ProcessImplicitLayersKey(HKEY key, const std::wstring &path, std::vector<std::string> *otherJSONs, bool deleteOthers) { bool thisRegistered = false; wchar_t name[1024] = {}; DWORD nameSize = 1024; DWORD idx = 0; LONG ret = RegEnumValueW(key, idx++, name, &nameSize, NULL, NULL, NULL, NULL); std::wstring myJSON = path; for(size_t i = 0; i < myJSON.size(); i++) myJSON[i] = towlower(myJSON[i]); while(ret == ERROR_SUCCESS) { // convert the name here so we preserve casing std::string utf8name = StringFormat::Wide2UTF8(name); for(DWORD i = 0; i <= nameSize && name[i]; i++) name[i] = towlower(name[i]); if(wcscmp(name, myJSON.c_str()) == 0) { thisRegistered = true; } else if(wcsstr(name, L"renderdoc.json") != NULL) { if(otherJSONs) otherJSONs->push_back(utf8name); if(deleteOthers) RegDeleteValueW(key, name); } nameSize = 1024; ret = RegEnumValueW(key, idx++, name, &nameSize, NULL, NULL, NULL, NULL); } return thisRegistered; }
BOOL DoLoadItems(void) { ITEMVECTOR Items; HKEY hKey = NULL; RegOpenKeyExW(HKEY_LOCAL_MACHINE, g_pszKey, 0, KEY_READ, &hKey); if (hKey == NULL) return FALSE; WCHAR szName[MAX_STRING], szValue[MAX_STRING]; DWORD cbName, cbValue; for (DWORD dwIndex = 0; ; ++dwIndex) { cbName = sizeof(szName); cbValue = sizeof(szValue); LONG Error = RegEnumValueW(hKey, dwIndex, szName, &cbName, NULL, NULL, (LPBYTE)szValue, &cbValue); if (Error != ERROR_SUCCESS) break; BYTE CharSet1 = DEFAULT_CHARSET, CharSet2 = DEFAULT_CHARSET; LPWSTR pch; pch = wcsrchr(szName, L','); if (pch) { *pch = 0; CharSet1 = (BYTE)_wtoi(pch + 1); } pch = wcsrchr(szValue, L','); if (pch) { *pch = 0; CharSet2 = (BYTE)_wtoi(pch + 1); } ITEM Item(szName, szValue, CharSet1, CharSet2); trim(Item.m_Name); trim(Item.m_Substitute); Items.push_back(Item); } RegCloseKey(hKey); g_Items = Items; LV_AddItems(g_hListView); DoSort(0, TRUE); g_bModified = FALSE; g_bNeedsReboot = FALSE; return !g_Items.empty(); }
static HRESULT enum_values( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT *types, VARIANT *retval ) { HKEY hkey = NULL; HRESULT hr = S_OK; BSTR *value_names = NULL; DWORD count, buflen, len, *value_types = NULL; LONG res, i = 0; WCHAR *buf = NULL; TRACE("%p, %s\n", root, debugstr_w(subkey)); if ((res = RegOpenKeyExW( root, subkey, 0, KEY_QUERY_VALUE, &hkey ))) goto done; if ((res = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, NULL, NULL, NULL, &count, &buflen, NULL, NULL, NULL ))) goto done; hr = E_OUTOFMEMORY; if (!(buf = heap_alloc( (buflen + 1) * sizeof(WCHAR) ))) goto done; if (!(value_names = heap_alloc( count * sizeof(BSTR) ))) goto done; if (!(value_types = heap_alloc( count * sizeof(DWORD) ))) goto done; hr = S_OK; for (;;) { len = buflen + 1; res = RegEnumValueW( hkey, i, buf, &len, NULL, &value_types[i], NULL, NULL ); if (res == ERROR_NO_MORE_ITEMS) { if (i) res = ERROR_SUCCESS; break; } if (res) break; if (!(value_names[i] = SysAllocString( buf ))) { for (i--; i >= 0; i--) SysFreeString( value_names[i] ); hr = ERROR_OUTOFMEMORY; break; } i++; } if (hr == S_OK && !res) { hr = to_bstr_array( value_names, i, names ); if (hr == S_OK) hr = to_i4_array( value_types, i, types ); } done: set_variant( VT_UI4, res, NULL, retval ); RegCloseKey( hkey ); heap_free( value_names ); heap_free( value_types ); heap_free( buf ); return hr; }
LONG Win32U_RegEnumValue(HKEY keyName, // IN DWORD index, // IN LPSTR valueName, // OUT: buffer LPDWORD valueNameSize, // IN/OUT: LPDWORD reserved, // IN: reserved LPDWORD type, // OUT: can be NULL LPBYTE data, // OUT: can be NULL LPDWORD dataSize) // OUT: can be NULL { LONG ret; utf16_t *valueNameW; DWORD valueNameSizeW = REG_MAX_VALUE_NAME_LEN+1; char *dataTemp = NULL; DWORD dataSizeTemp = 0; DWORD valueType; valueNameW = Util_SafeCalloc(valueNameSizeW, sizeof *valueNameW); if (data) { ASSERT(dataSize != NULL); dataSizeTemp = *dataSize * 2; dataTemp = Util_SafeMalloc(dataSizeTemp); } ret = RegEnumValueW(keyName, index, valueNameW, &valueNameSizeW /* # of characters */, reserved, &valueType, dataTemp, &dataSizeTemp /* # of bytes */); if (ret != ERROR_NO_MORE_ITEMS) { /* valueName is valid */ /* Attempt to convert value name back to UTF-8 */ if (!Win32UCodeSetUtf16leToUtf8(valueNameW, valueNameSizeW * 2, valueName, valueNameSize)) { ret = ERROR_MORE_DATA; } } ret = Win32UWriteBackRegData(dataTemp, dataSizeTemp, data, dataSize, valueType, ret); /* Write back the type information if asked for */ if (type) { *type = valueType; } free(valueNameW); free(dataTemp); return ret; }
static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_path) { static const WCHAR SystemRootW[] = {'S','y','s','t','e','m','R','o','o','t',0}; static const WCHAR SystemDriveW[] = {'S','y','s','t','e','m','D','r','i','v','e',0}; static const WCHAR PATHW[] = {'P','A','T','H'}; UNICODE_STRING us_name, us_value; WCHAR name[1024], value[1024]; DWORD ret, index, size; for (index = 0; ; index++) { size = sizeof(name)/sizeof(WCHAR); ret = RegEnumValueW(hkey, index, name, &size, NULL, NULL, NULL, NULL); if (ret != ERROR_SUCCESS) break; if (!memicmpW(name, SystemRootW, sizeof(SystemRootW)/sizeof(WCHAR))) continue; if (!memicmpW(name, SystemDriveW, sizeof(SystemDriveW)/sizeof(WCHAR))) continue; RtlInitUnicodeString(&us_name, name); us_value.Buffer = value; us_value.MaximumLength = sizeof(value); if (!memicmpW(name, PATHW, sizeof(PATHW)/sizeof(WCHAR)) && !RtlQueryEnvironmentVariable_U(*env, &us_name, &us_value)) { if (!set_path) continue; size = strlenW(value)+1; if (!get_reg_value(*env, hkey, name, value+size, sizeof(value)-size*sizeof(WCHAR))) continue; value[size] = ';'; RtlInitUnicodeString(&us_value, value); RtlSetEnvironmentVariable(env, &us_name, &us_value); continue; } if (!get_reg_value(*env, hkey, name, value, sizeof(value))) continue; if(!value[0]) continue; RtlInitUnicodeString(&us_value, value); RtlSetEnvironmentVariable(env, &us_name, &us_value); } }
static void OnInitMenu(HWND hWnd) { LONG lResult; HKEY hKey = NULL; DWORD dwIndex, cbValueName, cbValueData, dwType; WCHAR szValueName[256]; BYTE abValueData[256]; static int s_nFavoriteMenuSubPos = -1; HMENU hMenu; BOOL bDisplayedAny = FALSE; /* Find Favorites menu and clear it out */ hMenu = GetSubMenu(GetMenu(hWnd), FAVORITES_MENU_POSITION); if (!hMenu) goto done; if (s_nFavoriteMenuSubPos < 0) { s_nFavoriteMenuSubPos = GetMenuItemCount(hMenu); } else { while(RemoveMenu(hMenu, s_nFavoriteMenuSubPos, MF_BYPOSITION)) ; } lResult = RegOpenKeyW(HKEY_CURRENT_USER, s_szFavoritesRegKey, &hKey); if (lResult != ERROR_SUCCESS) goto done; dwIndex = 0; do { cbValueName = COUNT_OF(szValueName); cbValueData = sizeof(abValueData); lResult = RegEnumValueW(hKey, dwIndex, szValueName, &cbValueName, NULL, &dwType, abValueData, &cbValueData); if ((lResult == ERROR_SUCCESS) && (dwType == REG_SZ)) { if (!bDisplayedAny) { AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); bDisplayedAny = TRUE; } AppendMenu(hMenu, 0, ID_FAVORITES_MIN + GetMenuItemCount(hMenu), szValueName); } dwIndex++; } while(lResult == ERROR_SUCCESS); done: if (hKey) RegCloseKey(hKey); }
static void AddComponentCategories(void) { TVINSERTSTRUCTW tvis; HKEY hKey, hCurKey; WCHAR keyName[MAX_LOAD_STRING]; WCHAR valName[MAX_LOAD_STRING]; WCHAR buffer[MAX_LOAD_STRING]; LONG lenBuffer; DWORD lenBufferHlp; DWORD lenValName; int i=-1; U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_CHILDREN; U(tvis).item.cchTextMax = MAX_LOAD_STRING; tvis.hInsertAfter = TVI_FIRST; if(tree.hGBCC) tvis.hParent = tree.hGBCC; else tvis.hParent = TVI_ROOT; U(tvis).item.cChildren = 1; if(RegOpenKeyW(HKEY_CLASSES_ROOT, wszComponentCategories, &hKey) != ERROR_SUCCESS) return; while(TRUE) { i++; if(RegEnumKeyW(hKey, i, keyName, sizeof(keyName)/sizeof(keyName[0])) != ERROR_SUCCESS) break; if(RegOpenKeyW(hKey, keyName, &hCurKey) != ERROR_SUCCESS) continue; lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]); lenBufferHlp = sizeof(WCHAR[MAX_LOAD_STRING]); lenValName = sizeof(WCHAR[MAX_LOAD_STRING]); if(RegQueryValueW(hCurKey, NULL, buffer, &lenBuffer) == ERROR_SUCCESS && *buffer) U(tvis).item.pszText = buffer; else if(RegEnumValueW(hCurKey, 0, valName, &lenValName, NULL, NULL, (LPBYTE)buffer, &lenBufferHlp) == ERROR_SUCCESS && *buffer) U(tvis).item.pszText = buffer; else continue; RegCloseKey(hCurKey); U(tvis).item.lParam = CreateITEM_INFO(REGTOP, keyName, keyName, NULL); SendMessageW(globals.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis); } RegCloseKey(hKey); SendMessageW(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hGBCC); }
/************************************************************************** * CDesktopFolderEnumZ::CreateFontsEnumList() */ BOOL CDesktopFolderEnumZ::CreateFontsEnumList(DWORD dwFlags) { WCHAR szPath[MAX_PATH]; WCHAR szName[LF_FACESIZE+20]; WCHAR szFile[MAX_PATH]; LPWSTR pszPath; UINT Length; LONG ret; DWORD dwType, dwName, dwFile, dwIndex; LPITEMIDLIST pidl; HKEY hKey; if (dwFlags & SHCONTF_NONFOLDERS) { if (!SHGetSpecialFolderPathW(NULL, szPath, CSIDL_FONTS, FALSE)) return FALSE; pszPath = PathAddBackslashW(szPath); if (!pszPath) return FALSE; if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", 0, KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; Length = pszPath - szPath; dwIndex = 0; do { dwName = sizeof(szName) / sizeof(WCHAR); dwFile = sizeof(szFile) / sizeof(WCHAR); ret = RegEnumValueW(hKey, dwIndex++, szName, &dwName, NULL, &dwType, (LPBYTE)szFile, &dwFile); if (ret == ERROR_SUCCESS) { szFile[(sizeof(szFile)/sizeof(WCHAR))-1] = L'\0'; if (dwType == REG_SZ && wcslen(szFile) + Length + 1 < (sizeof(szPath) / sizeof(WCHAR))) { wcscpy(&szPath[Length], szFile); pidl = _ILCreateFontItem(szName, szPath); TRACE("pidl %p name %s path %s\n", pidl, debugstr_w(szName), debugstr_w(szPath)); if (pidl) { if (!AddToEnumList(pidl)) SHFree(pidl); } } } } while(ret != ERROR_NO_MORE_ITEMS); RegCloseKey(hKey); } return TRUE; }
UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct) { HKEY hkeyComp = 0; DWORD r, sz; WCHAR szValName[SQUISH_GUID_SIZE]; TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct); if (!szComponent || !*szComponent || !szProduct) return ERROR_INVALID_PARAMETER; if (MSIREG_OpenUserDataComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS && MSIREG_OpenLocalSystemComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS) return ERROR_UNKNOWN_COMPONENT; /* see if there are any products at all */ sz = SQUISH_GUID_SIZE; r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL); if (r != ERROR_SUCCESS) { RegCloseKey(hkeyComp); if (index != 0) return ERROR_INVALID_PARAMETER; return ERROR_UNKNOWN_COMPONENT; } sz = SQUISH_GUID_SIZE; r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL); if( r == ERROR_SUCCESS ) unsquash_guid(szValName, szProduct); RegCloseKey(hkeyComp); return r; }
bool WinRegKey::EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType) { LONG lRes; // enum the values lRes = RegEnumValueW(m_hKey, index, pValueName, pcchValueName, 0, pType, NULL, NULL); if (ERROR_SUCCESS != lRes) { DISPATCHER_LOG_OPERATION(SetLastError(lRes)); return false; } return true; } // bool WinRegKey::EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType)
nsresult gfxGDIFontList::GetFontSubstitutes() { HKEY hKey; DWORD i, rv, lenAlias, lenActual, valueType; WCHAR aliasName[MAX_VALUE_NAME]; WCHAR actualName[MAX_VALUE_DATA]; if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes", 0, KEY_READ, &hKey) != ERROR_SUCCESS) { return NS_ERROR_FAILURE; } for (i = 0, rv = ERROR_SUCCESS; rv != ERROR_NO_MORE_ITEMS; i++) { aliasName[0] = 0; lenAlias = sizeof(aliasName); actualName[0] = 0; lenActual = sizeof(actualName); rv = RegEnumValueW(hKey, i, aliasName, &lenAlias, NULL, &valueType, (LPBYTE)actualName, &lenActual); if (rv != ERROR_SUCCESS || valueType != REG_SZ || lenAlias == 0) { continue; } if (aliasName[0] == WCHAR('@')) { continue; } nsAutoString substituteName((PRUnichar*) aliasName); nsAutoString actualFontName((PRUnichar*) actualName); RemoveCharsetFromFontSubstitute(substituteName); BuildKeyNameFromFontName(substituteName); RemoveCharsetFromFontSubstitute(actualFontName); BuildKeyNameFromFontName(actualFontName); gfxFontFamily *ff; if (!actualFontName.IsEmpty() && (ff = mFontFamilies.GetWeak(actualFontName))) { mFontSubstitutes.Put(substituteName, ff); } else { mNonExistingFonts.AppendElement(substituteName); } } return NS_OK; }
NS_IMETHODIMP nsWindowsRegKey::GetValueName(PRUint32 index, nsAString &result) { NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); PRUnichar nameBuf[MAX_VALUE_NAME_LEN]; DWORD nameLen = sizeof(nameBuf) / sizeof(nameBuf[0]); LONG rv = RegEnumValueW(mKey, index, nameBuf, &nameLen, NULL, NULL, NULL, NULL); if (rv != ERROR_SUCCESS) return NS_ERROR_NOT_AVAILABLE; // XXX what's the best error code here? result.Assign(nameBuf, nameLen); return NS_OK; }
JNIEXPORT jobjectArray JNICALL Java_org_netbeans_installer_utils_system_windows_WindowsRegistry_getValueNames0(JNIEnv *jEnv, jobject jObject, jint jMode, jint jSection, jstring jKey) { HKEY hkey = 0; unsigned short* key = getWideChars(jEnv, jKey); DWORD valuesCount = 0; int err = 0; int index = 0; unsigned short* buffer = (unsigned short*) MALLOC(sizeof(char) * MAX_LEN_VALUE_NAME); jobjectArray result = NULL; if (RegOpenKeyExW(getHKEY(jSection), key, 0, KEY_QUERY_VALUE | getMode(jMode), &hkey) == ERROR_SUCCESS) { if (RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, NULL, NULL, &valuesCount, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { jclass stringClazz = (*jEnv)->FindClass(jEnv, "java/lang/String"); result = (*jEnv)->NewObjectArray(jEnv, valuesCount, stringClazz, NULL); do { DWORD size = MAX_LEN_VALUE_NAME; buffer[0] = 0; err = RegEnumValueW(hkey, index, buffer, &size, NULL, NULL, NULL, NULL); if (err == ERROR_SUCCESS) { (*jEnv)->SetObjectArrayElement(jEnv, result, index, getStringW(jEnv, buffer)); } else { if (err != ERROR_NO_MORE_ITEMS) { throwException(jEnv, "Cannot get value names"); } } index++; } while (err == ERROR_SUCCESS); } else { throwException(jEnv, "Cannot read key data"); } } else { throwException(jEnv, "Cannot open key"); } if (hkey != 0) { RegCloseKey(hkey); } FREE(key); FREE(buffer); return result; }
bool enumRegistryValue(HKEY parent, DWORD index, wxString& valueNameOut, wxString& valueOut) { valueNameOut.Clear(); valueOut.Clear(); WCHAR valueNameBuffer[512]; DWORD valueNameBufferSize = static_cast<DWORD>(sizeof(valueNameBuffer)); BYTE valueBuffer[512]; DWORD valueBufferSize = static_cast<DWORD>(sizeof(valueBuffer)); DWORD type; LONG ret = RegEnumValueW(parent, index, valueNameBuffer, &valueNameBufferSize, NULL, &type, valueBuffer, &valueBufferSize); if (ret != ERROR_SUCCESS) { return false; } valueNameOut = wxString(valueNameBuffer, valueNameBufferSize); switch (type) { case REG_BINARY: valueOut = wxString::From8BitData(reinterpret_cast<char*>(valueBuffer), valueBufferSize); break; case REG_DWORD: { ULONG val = *reinterpret_cast<ULONG*>(valueBuffer); // I feel dirty... valueOut << val; break; } case REG_QWORD: { ULONGLONG val = *reinterpret_cast<ULONGLONG*>(valueBuffer); // I feel dirty... valueOut << val; break; } case REG_SZ: valueOut = wxString(reinterpret_cast<wchar_t*>(valueBuffer), (valueBufferSize / sizeof(WCHAR)) - 1); break; default: return false; } return true; }
bool WinRegKey::EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType) { #if defined(MEDIASDK_USE_REGISTRY) || (!defined(MEDIASDK_UWP_LOADER) && !defined(MEDIASDK_UWP_PROCTABLE)) LONG lRes; // enum the values lRes = RegEnumValueW(m_hKey, index, pValueName, pcchValueName, 0, pType, NULL, NULL); if (ERROR_SUCCESS != lRes) { DISPATCHER_LOG_OPERATION(SetLastError(lRes)); return false; } return true; #else return false; #endif } // bool WinRegKey::EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType)
NS_IMETHODIMP nsWindowsRegKey::GetValueName(uint32_t aIndex, nsAString& aResult) { if (NS_WARN_IF(!mKey)) { return NS_ERROR_NOT_INITIALIZED; } wchar_t nameBuf[MAX_VALUE_NAME_LEN]; DWORD nameLen = sizeof(nameBuf) / sizeof(nameBuf[0]); LONG rv = RegEnumValueW(mKey, aIndex, nameBuf, &nameLen, nullptr, nullptr, nullptr, nullptr); if (rv != ERROR_SUCCESS) { return NS_ERROR_NOT_AVAILABLE; // XXX what's the best error code here? } aResult.Assign(nameBuf, nameLen); return NS_OK; }
LOCALE_LIST_NODE* LocaleList_Create(VOID) { WCHAR szValue[MAX_PATH]; DWORD dwIndex; DWORD dwSize; HKEY hKey; if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Nls\\Language", 0, KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) { return NULL; } dwSize = sizeof(szValue); dwIndex = 0; while (RegEnumValueW(hKey, dwIndex, szValue, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { WCHAR szName[MAX_STR_LEN]; DWORD dwId; dwId = DWORDfromString(szValue); if (GetLocaleInfoW(LOWORD(dwId), LOCALE_SLANGUAGE, szName, ARRAYSIZE(szName))) { LocaleList_Append(dwId, szName); } dwSize = sizeof(szValue); ++dwIndex; } return _LocaleList; }
UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct) { HKEY hkeyComp = 0; DWORD r, sz; WCHAR szValName[SQUISH_GUID_SIZE]; TRACE("%s %ld %p\n",debugstr_w(szComponent),index,szProduct); r = MSIREG_OpenComponentsKey(szComponent,&hkeyComp,FALSE); if( r != ERROR_SUCCESS ) return ERROR_NO_MORE_ITEMS; sz = SQUISH_GUID_SIZE; r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL); if( r == ERROR_SUCCESS ) unsquash_guid(szValName, szProduct); RegCloseKey(hkeyComp); return r; }
UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index, LPWSTR szFeature, LPWSTR szParent) { HKEY hkeyProduct = 0; DWORD r, sz; TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent); if( !szProduct ) return ERROR_INVALID_PARAMETER; r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE); if( r != ERROR_SUCCESS ) return ERROR_NO_MORE_ITEMS; sz = GUID_SIZE; r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL); RegCloseKey(hkeyProduct); return r; }
void UnregisterAllKFsAddedByThisTool(DWORD *pdwKFs) { *pdwKFs = 0; HKEY hKey; if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, SZ_REG_PATH_HISTORY, 0, KEY_ALL_ACCESS, &hKey)) { DWORD dwValues = 0; DWORD cchMaxValueNameLen = 0; if (ERROR_SUCCESS == RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &dwValues, &cchMaxValueNameLen, NULL, NULL, NULL)) { DWORD const cchValName = cchMaxValueNameLen + 1; // add 1 for trailing NULL PWSTR pszValName = (PWSTR)CoTaskMemAlloc(sizeof(WCHAR) * cchValName); if (pszValName) { for (DWORD dw = 0; dw < dwValues; ++dw) { DWORD cchValNameInOut = cchValName; if (ERROR_SUCCESS == RegEnumValueW(hKey, dw, pszValName, &cchValNameInOut, NULL, NULL, NULL, NULL)) { KNOWNFOLDERID kfid = GUID_NULL; CLSIDFromString(pszValName, &kfid); RemovePhysicalFolder(kfid); HRESULT hr = UnregisterFolder(kfid); if (SUCCEEDED(hr)) { ++*pdwKFs; } else { wprintf(L"Failed to UnregisterFolder %s hr=0x%x\n", pszValName, hr); } } } CoTaskMemFree(pszValName); } } RegDeleteTree(hKey, NULL); RegCloseKey(hKey); } }
BOOL MainWnd_OnUpdateRegistry(HWND hwnd) { // open the key HKEY hKey = NULL; RegOpenKeyExW(HKEY_LOCAL_MACHINE, g_pszKey, 0, KEY_ALL_ACCESS, &hKey); if (hKey == NULL) return FALSE; // clear all values WCHAR szName[MAX_STRING], szValue[MAX_STRING]; DWORD cbName, cbValue; for (;;) { cbName = sizeof(szName); cbValue = sizeof(szValue); LONG Error = RegEnumValueW(hKey, 0, szName, &cbName, NULL, NULL, (LPBYTE)szValue, &cbValue); if (Error != ERROR_SUCCESS) break; RegDeleteValueW(hKey, szName); } // set values size_t Count = g_Items.size(); for (size_t i = 0; i < Count; ++i) { DWORD cbData = (g_Items[i].m_Substitute.size() + 1) * sizeof(WCHAR); RegSetValueExW(hKey, g_Items[i].m_Name.c_str(), 0, REG_SZ, (LPBYTE)g_Items[i].m_Substitute.c_str(), cbData); } // close now RegCloseKey(hKey); g_bModified = FALSE; g_bNeedsReboot = TRUE; return TRUE; }
JNIEXPORT jboolean JNICALL Java_net_rubygrapefruit_platform_internal_jni_WindowsRegistryFunctions_getValueNames(JNIEnv *env, jclass target, jint keyNum, jstring subkey, jobject names, jobject result) { wchar_t* subkeyStr = java_to_wchar(env, subkey, result); jclass names_class = env->GetObjectClass(names); jmethodID method = env->GetMethodID(names_class, "add", "(Ljava/lang/Object;)Z"); HKEY key; LONG retval = RegOpenKeyExW(get_key_from_ordinal(keyNum), subkeyStr, 0, KEY_READ, &key); if (retval != ERROR_SUCCESS) { free(subkeyStr); if (retval != ERROR_FILE_NOT_FOUND) { mark_failed_with_code(env, "could open registry key", retval, NULL, result); } return false; } DWORD valueCount; DWORD maxValueNameLen; retval = RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL, &valueCount, &maxValueNameLen, NULL, NULL, NULL); if (retval != ERROR_SUCCESS) { mark_failed_with_code(env, "could query registry key", retval, NULL, result); } else { wchar_t* valueNameStr = (wchar_t*)malloc(sizeof(wchar_t) * (maxValueNameLen+1)); for (int i = 0; i < valueCount; i++) { DWORD valueNameLen = maxValueNameLen + 1; retval = RegEnumValueW(key, i, valueNameStr, &valueNameLen, NULL, NULL, NULL, NULL); if (retval != ERROR_SUCCESS) { mark_failed_with_code(env, "could enumerate registry value name", retval, NULL, result); break; } env->CallVoidMethod(names, method, wchar_to_java(env, valueNameStr, wcslen(valueNameStr), result)); } free(valueNameStr); } RegCloseKey(key); free(subkeyStr); return true; }