static HRESULT WINAPI DEVENUM_IEnumMoniker_Next(IEnumMoniker *iface, ULONG celt, IMoniker **rgelt, ULONG *pceltFetched) { EnumMonikerImpl *This = impl_from_IEnumMoniker(iface); WCHAR buffer[MAX_PATH + 1]; LONG res; ULONG fetched = 0; MediaCatMoniker * pMoniker; TRACE("(%p)->(%d, %p, %p)\n", iface, celt, rgelt, pceltFetched); while (fetched < celt) { if(This->index+fetched < This->subkey_cnt) res = RegEnumKeyW(This->hkey, This->index+fetched, buffer, sizeof(buffer) / sizeof(WCHAR)); else if(This->special_hkey) res = RegEnumKeyW(This->special_hkey, This->index+fetched-This->subkey_cnt, buffer, sizeof(buffer) / sizeof(WCHAR)); else break; if (res != ERROR_SUCCESS) { break; } pMoniker = DEVENUM_IMediaCatMoniker_Construct(); if (!pMoniker) return E_OUTOFMEMORY; if (RegOpenKeyW(This->index+fetched < This->subkey_cnt ? This->hkey : This->special_hkey, buffer, &pMoniker->hkey) != ERROR_SUCCESS) { IMoniker_Release(&pMoniker->IMoniker_iface); break; } rgelt[fetched] = &pMoniker->IMoniker_iface; fetched++; } This->index += fetched; TRACE("-- fetched %d\n", fetched); if (pceltFetched) *pceltFetched = fetched; if (fetched != celt) return S_FALSE; else return S_OK; }
/************************************************************************* * MsiEnumRelatedProductsW [MSI.@] * */ UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved, DWORD iProductIndex, LPWSTR lpProductBuf) { UINT r; HKEY hkey; WCHAR szKeyName[SQUISH_GUID_SIZE]; TRACE("%s %lu %lu %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 = RegEnumKeyW(hkey, iProductIndex, szKeyName, SQUISH_GUID_SIZE); if( r == ERROR_SUCCESS ) unsquash_guid(szKeyName, lpProductBuf); RegCloseKey(hkey); return r; }
static BOOL load_mozilla(PRUnichar *gre_path) { DWORD res, type, i, size = MAX_PATH; HKEY mozilla_key, hkey; WCHAR key_name[100]; BOOL ret = FALSE; static const WCHAR wszGreKey[] = {'S','o','f','t','w','a','r','e','\\', 'm','o','z','i','l','l','a','.','o','r','g','\\', 'G','R','E',0}; static const WCHAR wszGreHome[] = {'G','r','e','H','o','m','e',0}; res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszGreKey, &mozilla_key); if(res != ERROR_SUCCESS) { TRACE("Could not open key %s\n", debugstr_w(wszGreKey)); return FALSE; } for(i=0; !ret && RegEnumKeyW(mozilla_key, i, key_name, sizeof(key_name)/sizeof(WCHAR)) == ERROR_SUCCESS; i++) { RegOpenKeyW(mozilla_key, key_name, &hkey); res = RegQueryValueExW(hkey, wszGreHome, NULL, &type, (LPBYTE)gre_path, &size); if(res == ERROR_SUCCESS) ret = TRUE; RegCloseKey(hkey); } RegCloseKey(mozilla_key); return ret ? load_xpcom(gre_path) : FALSE; }
/*********************************************************************** * GetKeyboardLayoutList (USER32.@) * * Return number of values available if either input parm is * 0, per MS documentation. */ UINT WINAPI GetKeyboardLayoutList(INT nBuff, HKL *layouts) { HKEY hKeyKeyboard; DWORD rc; INT count = 0; ULONG_PTR baselayout; LANGID langid; static const WCHAR szKeyboardReg[] = {'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\','C','o','n','t','r','o','l','\\','K','e','y','b','o','a','r','d',' ','L','a','y','o','u','t','s',0}; TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts); baselayout = GetUserDefaultLCID(); langid = PRIMARYLANGID(LANGIDFROMLCID(baselayout)); if (langid == LANG_CHINESE || langid == LANG_JAPANESE || langid == LANG_KOREAN) baselayout |= 0xe001 << 16; /* IME */ else baselayout |= baselayout << 16; /* Enumerate the Registry */ rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,szKeyboardReg,&hKeyKeyboard); if (rc == ERROR_SUCCESS) { do { WCHAR szKeyName[9]; HKL layout; rc = RegEnumKeyW(hKeyKeyboard, count, szKeyName, 9); if (rc == ERROR_SUCCESS) { layout = (HKL)strtoulW(szKeyName,NULL,16); if (baselayout != 0 && layout == (HKL)baselayout) baselayout = 0; /* found in the registry do not add again */ if (nBuff && layouts) { if (count >= nBuff ) break; layouts[count] = layout; } count ++; } } while (rc == ERROR_SUCCESS); RegCloseKey(hKeyKeyboard); } /* make sure our base layout is on the list */ if (baselayout != 0) { if (nBuff && layouts) { if (count < nBuff) { layouts[count] = (HKL)baselayout; count++; } } else count++; } return count; }
BOOL My_RegEnumKeyW() { HKEY hKey=NULL; DWORD dwIndex=NULL; LPWSTR lpName=NULL; DWORD cbName=NULL; LONG returnVal_Real = NULL; LONG returnVal_Intercepted = NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; disableInterception(); returnVal_Real = RegEnumKeyW (hKey,dwIndex,lpName,cbName); error_Real = GetLastError(); enableInterception(); returnVal_Intercepted = RegEnumKeyW (hKey,dwIndex,lpName,cbName); error_Intercepted = GetLastError(); return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted)); }
BOOL CNewMenu::LoadAllItems() { DWORD dwIndex = 0; WCHAR wszName[MAX_PATH]; SHELLNEW_ITEM *pNewItem; SHELLNEW_ITEM *pCurItem = NULL; /* If there are any unload them */ UnloadAllItems(); /* Enumerate all extesions */ while (RegEnumKeyW(HKEY_CLASSES_ROOT, dwIndex++, wszName, _countof(wszName)) == ERROR_SUCCESS) { if (wszName[0] != L'.') continue; pNewItem = LoadItem(wszName); if (pNewItem) { if (wcsicmp(pNewItem->pwszExt, L".lnk") == 0) { /* Link handler */ m_pLinkItem = pNewItem; } else { /* Add at the end of list */ if (pCurItem) { pCurItem->pNext = pNewItem; pCurItem = pNewItem; } else pCurItem = m_pItems = pNewItem; } } } if (!m_pLinkItem) { m_pLinkItem = static_cast<SHELLNEW_ITEM *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHELLNEW_ITEM))); if (m_pLinkItem) { m_pLinkItem->Type = SHELLNEW_TYPE_NULLFILE; m_pLinkItem->pwszDesc = _wcsdup(L"Link"); m_pLinkItem->pwszExt = _wcsdup(L".lnk"); } } if (m_pItems == NULL) return FALSE; else return TRUE; }
BOOL HCR_GetDefaultVerbW( HKEY hkeyClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len ) { WCHAR sTemp[MAX_PATH]; LONG size; HKEY hkey; TRACE("%p %s %p\n", hkeyClass, debugstr_w(szVerb), szDest); if (szVerb && *szVerb) { lstrcpynW(szDest, szVerb, len); return TRUE; } size=len; *szDest='\0'; if (!RegQueryValueW(hkeyClass, swShell, szDest, &size) && *szDest) { /* The MSDN says to first try the default verb */ lstrcpyW(sTemp, swShell); lstrcatW(sTemp, szDest); lstrcatW(sTemp, swCommand); if (!RegOpenKeyExW(hkeyClass, sTemp, 0, 0, &hkey)) { RegCloseKey(hkey); TRACE("default verb=%s\n", debugstr_w(szDest)); return TRUE; } } /* then fallback to 'open' */ lstrcpyW(sTemp, swShell); lstrcatW(sTemp, swOpen); lstrcatW(sTemp, swCommand); if (!RegOpenKeyExW(hkeyClass, sTemp, 0, 0, &hkey)) { RegCloseKey(hkey); lstrcpynW(szDest, swOpen, len); TRACE("default verb=open\n"); return TRUE; } /* and then just use the first verb on Windows >= 2000 */ if (!RegEnumKeyW(hkeyClass, 0, szDest, len) && *szDest) { TRACE("default verb=first verb=%s\n", debugstr_w(szDest)); return TRUE; } TRACE("no default verb!\n"); return FALSE; }
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); }
static BOOL MIDIMAP_LoadSettingsScheme(MIDIMAPDATA* mom, const WCHAR* scheme) { HKEY hSchemesKey, hKey, hPortKey; unsigned i, idx, dev; WCHAR buffer[256], port[256]; DWORD type, size, mask; for (i = 0; i < 16; i++) mom->ChannelMap[i] = NULL; if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\MediaProperties\\PrivateProperties\\Midi\\Schemes", &hSchemesKey)) { return FALSE; } if (RegOpenKeyW(hSchemesKey, scheme, &hKey)) { RegCloseKey(hSchemesKey); return FALSE; } for (idx = 0; !RegEnumKeyW(hKey, idx, buffer, sizeof(buffer)/sizeof(buffer[0])); idx++) { if (RegOpenKeyW(hKey, buffer, &hPortKey)) continue; size = sizeof(port); if (RegQueryValueExW(hPortKey, NULL, 0, &type, (void*)port, &size)) continue; if (!MIDIMAP_FindPort(port, &dev)) continue; size = sizeof(mask); if (RegQueryValueExA(hPortKey, "Channels", 0, &type, (void*)&mask, &size)) continue; for (i = 0; i < 16; i++) { if (mask & (1 << i)) { if (mom->ChannelMap[i]) ERR("Quirks in registry, channel %u is mapped twice\n", i); mom->ChannelMap[i] = &midiOutPorts[dev]; } } } RegCloseKey(hSchemesKey); RegCloseKey(hKey); return TRUE; }
static HRESULT enum_key( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT *retval ) { HKEY hkey; HRESULT hr = S_OK; WCHAR buf[256]; BSTR *strings, *tmp; DWORD count = 2, len = sizeof(buf)/sizeof(buf[0]); LONG res, i = 0; TRACE("%p, %s\n", root, debugstr_w(subkey)); if (!(strings = heap_alloc( count * sizeof(BSTR) ))) return E_OUTOFMEMORY; if ((res = RegOpenKeyExW( root, subkey, 0, KEY_ENUMERATE_SUB_KEYS, &hkey ))) { set_variant( VT_UI4, res, NULL, retval ); heap_free( strings ); return S_OK; } for (;;) { if (i >= count) { count *= 2; if (!(tmp = heap_realloc( strings, count * sizeof(BSTR) ))) { RegCloseKey( hkey ); return E_OUTOFMEMORY; } strings = tmp; } if ((res = RegEnumKeyW( hkey, i, buf, len )) == ERROR_NO_MORE_ITEMS) { if (i) res = ERROR_SUCCESS; break; } if (res) break; if (!(strings[i] = SysAllocString( buf ))) { for (i--; i >= 0; i--) SysFreeString( strings[i] ); hr = ERROR_OUTOFMEMORY; break; } i++; } if (hr == S_OK && !res) hr = to_bstr_array( strings, i, names ); set_variant( VT_UI4, res, NULL, retval ); RegCloseKey( hkey ); heap_free( strings ); return hr; }
void CVstPluginManager::EnumerateDirectXDMOs() //-------------------------------------------- { HKEY hkEnum; WCHAR keyname[128]; LONG cr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "software\\classes\\DirectShow\\MediaObjects\\Categories\\f3602b3f-0592-48df-a4cd-674721e7ebeb", 0, KEY_READ, &hkEnum); DWORD index = 0; while (cr == ERROR_SUCCESS) { if ((cr = RegEnumKeyW(hkEnum, index, keyname, CountOf(keyname))) == ERROR_SUCCESS) { CLSID clsid; std::wstring formattedKey = std::wstring(L"{") + std::wstring(keyname) + std::wstring(L"}"); if(Util::StringToCLSID(formattedKey, clsid)) { HKEY hksub; formattedKey = std::wstring(L"software\\classes\\DirectShow\\MediaObjects\\") + std::wstring(keyname); if (RegOpenKeyW(HKEY_LOCAL_MACHINE, formattedKey.c_str(), &hksub) == ERROR_SUCCESS) { WCHAR name[64]; DWORD datatype = REG_SZ; DWORD datasize = sizeof(name); if(ERROR_SUCCESS == RegQueryValueExW(hksub, nullptr, 0, &datatype, (LPBYTE)name, &datasize)) { mpt::String::SetNullTerminator(name); StringFromGUID2(clsid, keyname, 100); VSTPluginLib *plug = new (std::nothrow) VSTPluginLib(mpt::PathString::FromNative(keyname), mpt::PathString::FromNative(name)); if(plug != nullptr) { pluginList.push_back(plug); plug->pluginId1 = kDmoMagic; plug->pluginId2 = clsid.Data1; plug->category = VSTPluginLib::catDMO; #ifdef DMO_LOG Log(mpt::String::PrintW(L"Found \"%1\" clsid=%2\n", plug->libraryName, plug->dllPath)); #endif } } RegCloseKey(hksub); } } } index++; } if (hkEnum) RegCloseKey(hkEnum); }
static bool DeleteRegistryKey(HKEY hKey, const wchar_t *szSubKey) { HKEY ckey; // Open the key if (RegOpenKeyExW(hKey, szSubKey, 0, KEY_ALL_ACCESS, &ckey) != ERROR_SUCCESS) return false; // Delete all subkeys wchar_t strChild[1024 + 1]; while (RegEnumKeyW(ckey, 0, strChild, 1024) == ERROR_SUCCESS) if (!DeleteRegistryKey(ckey, strChild)) return false; // Close the key RegCloseKey(ckey); // Delete the key if (RegDeleteKeyW(hKey, szSubKey) != ERROR_SUCCESS) return false; // Success return true; }
static BOOL ViewTree_LoadAll(VOID) { static const WCHAR s_szAdvanced[] = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"; // free if already existed if (s_ViewTreeEntries) { free(s_ViewTreeEntries); s_ViewTreeEntries = NULL; } s_ViewTreeEntryCount = 0; HKEY hKey; if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, s_szAdvanced, 0, KEY_READ, &hKey) != ERROR_SUCCESS) { return FALSE; // failure } // load the children WCHAR szKeyName[64]; DWORD dwIndex = 0; while (RegEnumKeyW(hKey, dwIndex, szKeyName, _countof(szKeyName)) == ERROR_SUCCESS) { HKEY hkeyChild; if (RegOpenKeyExW(hKey, szKeyName, 0, KEY_READ, &hkeyChild) != ERROR_SUCCESS) { ++dwIndex; continue; // failure } ViewTree_LoadTree(hkeyChild, szKeyName, DWORD(-1)); RegCloseKey(hkeyChild); ++dwIndex; } RegCloseKey(hKey); return TRUE; // success }
UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid) { HKEY hkeyComponents = 0; DWORD r; WCHAR szKeyName[SQUISH_GUID_SIZE]; TRACE("%d %p\n", index, lpguid); r = MSIREG_OpenComponents(&hkeyComponents); if( r != ERROR_SUCCESS ) return ERROR_NO_MORE_ITEMS; r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE); if( r == ERROR_SUCCESS ) unsquash_guid(szKeyName, lpguid); RegCloseKey(hkeyComponents); return r; }
static HRESULT WINAPI DEVENUM_IEnumMoniker_Next(LPENUMMONIKER iface, ULONG celt, IMoniker ** rgelt, ULONG * pceltFetched) { WCHAR buffer[MAX_PATH + 1]; LONG res; ULONG fetched = 0; MediaCatMoniker * pMoniker; EnumMonikerImpl *This = (EnumMonikerImpl *)iface; TRACE("(%p)->(%d, %p, %p)\n", iface, celt, rgelt, pceltFetched); while (fetched < celt) { res = RegEnumKeyW(This->hkey, This->index, buffer, sizeof(buffer) / sizeof(WCHAR)); if (res != ERROR_SUCCESS) { break; } pMoniker = DEVENUM_IMediaCatMoniker_Construct(); if (!pMoniker) return E_OUTOFMEMORY; if (RegOpenKeyW(This->hkey, buffer, &pMoniker->hkey) != ERROR_SUCCESS) { DEVENUM_IMediaCatMoniker_Release((LPMONIKER)pMoniker); break; } rgelt[fetched] = (LPMONIKER)pMoniker; fetched++; } This->index += fetched; TRACE("-- fetched %d\n", fetched); if (pceltFetched) *pceltFetched = fetched; if (fetched != celt) return S_FALSE; else return S_OK; }
static void AddInterfaces(void) { TVINSERTSTRUCTW tvis; HKEY hKey, hCurKey; WCHAR valName[MAX_LOAD_STRING]; WCHAR buffer[MAX_LOAD_STRING]; LONG lenBuffer; int i=-1; U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM; U(tvis).item.cchTextMax = MAX_LOAD_STRING; tvis.hInsertAfter = TVI_FIRST; tvis.hParent = tree.hI; if(RegOpenKeyW(HKEY_CLASSES_ROOT, wszInterface, &hKey) != ERROR_SUCCESS) return; while(TRUE) { i++; if(RegEnumKeyW(hKey, i, valName, sizeof(valName)/sizeof(valName[0])) != ERROR_SUCCESS) break; if(RegOpenKeyW(hKey, valName, &hCurKey) != ERROR_SUCCESS) continue; lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]); if(RegQueryValueW(hCurKey, NULL, buffer, &lenBuffer) == ERROR_SUCCESS && *buffer) U(tvis).item.pszText = buffer; else U(tvis).item.pszText = valName; RegCloseKey(hCurKey); U(tvis).item.lParam = CreateITEM_INFO(REGPATH|INTERFACE, valName, valName, NULL); SendMessageW(globals.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis); } RegCloseKey(hKey); SendMessageW(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hI); }
UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid) { HKEY hkeyProducts = 0; DWORD r; WCHAR szKeyName[SQUISH_GUID_SIZE]; TRACE("%d %p\n", index, lpguid); if (NULL == lpguid) return ERROR_INVALID_PARAMETER; r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Products, &hkeyProducts); if( r != ERROR_SUCCESS ) return ERROR_NO_MORE_ITEMS; r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE); if( r == ERROR_SUCCESS ) unsquash_guid(szKeyName, lpguid); RegCloseKey(hkeyProducts); return r; }
UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid) { HKEY hkeyFeatures = 0; DWORD r; WCHAR szKeyName[SQUISH_GUID_SIZE]; TRACE("%ld %p\n",index,lpguid); if (NULL == lpguid) return ERROR_INVALID_PARAMETER; r = MSIREG_OpenFeatures(&hkeyFeatures); if( r != ERROR_SUCCESS ) return ERROR_NO_MORE_ITEMS; r = RegEnumKeyW(hkeyFeatures, index, szKeyName, SQUISH_GUID_SIZE); if( r == ERROR_SUCCESS ) unsquash_guid(szKeyName, lpguid); RegCloseKey(hkeyFeatures); return r; }
HRESULT enum_services_providers(const GUID * const service, DPN_SERVICE_PROVIDER_INFO * const info_buffer, DWORD * const buf_size, DWORD * const returned) { static const WCHAR serviceproviders[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\', 'D','i','r','e','c','t','P','l','a','y','8','\\', 'S','e','r','v','i','c','e',' ','P','r','o','v','i','d','e','r','s',0}; static const WCHAR friendly[] = {'F','r','i','e','n','d','l','y',' ','N','a','m','e',0}; static const WCHAR dp_adapterW[] = {'L','o','c','a','l',' ','A','r','e','a',' ','C','o','n','n','e','c','t','i','o','n', ' ','-',' ','I','P','v','4',0}; static const GUID adapter_guid = {0x4ce725f6, 0xd3c0, 0xdade, {0xba, 0x6f, 0x11, 0xf9, 0x65, 0xbc, 0x42, 0x99}}; DWORD req_size = 0; LONG res; HKEY key = NULL; LONG next_key; DWORD index = 0; WCHAR provider[MAX_PATH]; DWORD size; if(!returned || !buf_size) return E_POINTER; if(!service) { *returned = 0; res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, serviceproviders, 0, KEY_READ, &key); if(res == ERROR_FILE_NOT_FOUND) return DPNERR_DOESNOTEXIST; next_key = RegEnumKeyW( key, index, provider, MAX_PATH); while(next_key == ERROR_SUCCESS) { res = RegGetValueW(key, provider, friendly, RRF_RT_REG_SZ, NULL, NULL, &size); if(res == ERROR_SUCCESS) { req_size += sizeof(DPN_SERVICE_PROVIDER_INFO) + size; (*returned)++; } index++; next_key = RegEnumKeyW( key, index, provider, MAX_PATH ); } } else if(IsEqualGUID(service, &CLSID_DP8SP_TCPIP)) { req_size = sizeof(DPN_SERVICE_PROVIDER_INFO) + sizeof(dp_adapterW); } else { FIXME("Application requested a provider we don't handle (yet)\n"); return DPNERR_DOESNOTEXIST; } if(*buf_size < req_size) { RegCloseKey(key); *buf_size = req_size; return DPNERR_BUFFERTOOSMALL; } if(!service) { int offset = 0; int count = 0; char *infoend = ((char *)info_buffer + (sizeof(DPN_SERVICE_PROVIDER_INFO) * (*returned))); index = 0; next_key = RegEnumKeyW( key, index, provider, MAX_PATH); while(next_key == ERROR_SUCCESS) { res = RegGetValueW(key, provider, friendly, RRF_RT_REG_SZ, NULL, NULL, &size); if(res == ERROR_SUCCESS) { info_buffer[count].guid = CLSID_DP8SP_TCPIP; info_buffer[count].pwszName = (LPWSTR)(infoend + offset); RegGetValueW(key, provider, friendly, RRF_RT_REG_SZ, NULL, info_buffer[count].pwszName, &size); offset += size; count++; } index++; next_key = RegEnumKeyW(key, index, provider, MAX_PATH); } } else { info_buffer->pwszName = (LPWSTR)(info_buffer + 1); lstrcpyW(info_buffer->pwszName, dp_adapterW); info_buffer->guid = adapter_guid; *returned = 1; } RegCloseKey(key); return DPN_OK; }
static void locate_pythons_for_key(HKEY root, REGSAM flags) { HKEY core_root, ip_key; LSTATUS status = RegOpenKeyExW(root, CORE_PATH, 0, flags, &core_root); wchar_t message[MSGSIZE]; DWORD i; size_t n; BOOL ok; DWORD type, data_size, attrs; INSTALLED_PYTHON * ip, * pip; wchar_t ip_version[IP_VERSION_SIZE]; wchar_t ip_path[IP_SIZE]; wchar_t * check; wchar_t ** checkp; wchar_t *key_name = (root == HKEY_LOCAL_MACHINE) ? L"HKLM" : L"HKCU"; if (status != ERROR_SUCCESS) debug(L"locate_pythons_for_key: unable to open PythonCore key in %ls\n", key_name); else { ip = &installed_pythons[num_installed_pythons]; for (i = 0; num_installed_pythons < MAX_INSTALLED_PYTHONS; i++) { status = RegEnumKeyW(core_root, i, ip_version, IP_VERSION_SIZE); if (status != ERROR_SUCCESS) { if (status != ERROR_NO_MORE_ITEMS) { /* unexpected error */ winerror(status, message, MSGSIZE); debug(L"Can't enumerate registry key for version %ls: %ls\n", ip_version, message); } break; } else { wcsncpy_s(ip->version, MAX_VERSION_SIZE, ip_version, MAX_VERSION_SIZE-1); _snwprintf_s(ip_path, IP_SIZE, _TRUNCATE, L"%ls\\%ls\\InstallPath", CORE_PATH, ip_version); status = RegOpenKeyExW(root, ip_path, 0, flags, &ip_key); if (status != ERROR_SUCCESS) { winerror(status, message, MSGSIZE); // Note: 'message' already has a trailing \n debug(L"%ls\\%ls: %ls", key_name, ip_path, message); continue; } data_size = sizeof(ip->executable) - 1; status = RegQueryValueExW(ip_key, NULL, NULL, &type, (LPBYTE)ip->executable, &data_size); RegCloseKey(ip_key); if (status != ERROR_SUCCESS) { winerror(status, message, MSGSIZE); debug(L"%ls\\%ls: %ls\n", key_name, ip_path, message); continue; } if (type == REG_SZ) { data_size = data_size / sizeof(wchar_t) - 1; /* for NUL */ if (ip->executable[data_size - 1] == L'\\') --data_size; /* reg value ended in a backslash */ /* ip->executable is data_size long */ for (checkp = location_checks; *checkp; ++checkp) { check = *checkp; _snwprintf_s(&ip->executable[data_size], MAX_PATH - data_size, MAX_PATH - data_size, L"%ls%ls", check, PYTHON_EXECUTABLE); attrs = GetFileAttributesW(ip->executable); if (attrs == INVALID_FILE_ATTRIBUTES) { winerror(GetLastError(), message, MSGSIZE); debug(L"locate_pythons_for_key: %ls: %ls", ip->executable, message); } else if (attrs & FILE_ATTRIBUTE_DIRECTORY) { debug(L"locate_pythons_for_key: '%ls' is a \ directory\n", ip->executable, attrs); } else if (find_existing_python(ip->executable)) { debug(L"locate_pythons_for_key: %ls: already \ found\n", ip->executable); } else { /* check the executable type. */ ok = GetBinaryTypeW(ip->executable, &attrs); if (!ok) { debug(L"Failure getting binary type: %ls\n", ip->executable); } else { if (attrs == SCS_64BIT_BINARY) ip->bits = 64; else if (attrs == SCS_32BIT_BINARY) ip->bits = 32; else ip->bits = 0; if (ip->bits == 0) { debug(L"locate_pythons_for_key: %ls: \ invalid binary type: %X\n", ip->executable, attrs); } else { if (wcschr(ip->executable, L' ') != NULL) { /* has spaces, so quote */ n = wcslen(ip->executable); memmove(&ip->executable[1], ip->executable, n * sizeof(wchar_t)); ip->executable[0] = L'\"'; ip->executable[n + 1] = L'\"'; ip->executable[n + 2] = L'\0'; } debug(L"locate_pythons_for_key: %ls \ is a %dbit executable\n", ip->executable, ip->bits); ++num_installed_pythons; pip = ip++; if (num_installed_pythons >= MAX_INSTALLED_PYTHONS) break; /* Copy over the attributes for the next */ *ip = *pip; } } } }
BOOL GetIIDForName(LPCWSTR lpName, IID* riid) { HKEY hRoot = nullptr; ULONG status; status = RegOpenKeyEx(HKEY_CLASSES_ROOT, L"Interface", 0, KEY_ENUMERATE_SUB_KEYS, &hRoot); if (status == 0) { WCHAR keyName[128]; DWORD index = 0; BOOL foundKey = FALSE; while (true) { HKEY hSubKey; status = RegEnumKeyW(hRoot, index, keyName, _countof(keyName)); if (status != 0) { break; } index++; status = RegOpenKeyEx(hRoot, keyName, 0, KEY_QUERY_VALUE, &hSubKey); if (status != 0) { continue; } DWORD dwType; WCHAR valueName[256]; DWORD dwSize = sizeof(valueName)-sizeof(WCHAR); status = RegQueryValueEx(hSubKey, nullptr, nullptr, &dwType, (BYTE*)valueName, &dwSize); RegCloseKey(hSubKey); if ((status != 0) || (dwType != REG_SZ)) { continue; } // Ensure NUL terminate valueName[dwSize / sizeof(WCHAR)] = 0; if (_wcsicmp(valueName, lpName) == 0) { foundKey = TRUE; break; } } RegCloseKey(hRoot); if (foundKey) { return SUCCEEDED(IIDFromString(keyName, riid)); } } else { DebugPrintf("Could not open Interface key %d\n", status); } return FALSE; }
static void AddTypeLib(void) { TVINSERTSTRUCTW tvis; HKEY hKey, hCurKey, hInfoKey, hPath; WCHAR valName[MAX_LOAD_STRING]; WCHAR valParent[MAX_LOAD_STRING]; WCHAR buffer[MAX_LOAD_STRING]; WCHAR wszVer[MAX_LOAD_STRING]; WCHAR wszPath[MAX_LOAD_STRING]; const WCHAR wszFormat[] = { ' ','(','%','s',' ','%','s',')','\0' }; const WCHAR wszFormat2[] = { '%','s','\\','%','s','\0' }; LONG lenBuffer; int i=-1, j; U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM; U(tvis).item.cchTextMax = MAX_LOAD_STRING; tvis.hInsertAfter = TVI_FIRST; tvis.hParent = tree.hTL; if(RegOpenKeyW(HKEY_CLASSES_ROOT, wszTypeLib, &hKey) != ERROR_SUCCESS) return; while(TRUE) { i++; if(RegEnumKeyW(hKey, i, valParent, sizeof(valParent)/sizeof(valParent[0])) != ERROR_SUCCESS) break; if(RegOpenKeyW(hKey, valParent, &hCurKey) != ERROR_SUCCESS) continue; j = -1; while(TRUE) { j++; if(RegEnumKeyW(hCurKey, j, valName, sizeof(valName)/sizeof(valName[0])) != ERROR_SUCCESS) break; if(RegOpenKeyW(hCurKey, valName, &hInfoKey) != ERROR_SUCCESS) continue; lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]); if(RegQueryValueW(hInfoKey, NULL, buffer, &lenBuffer) == ERROR_SUCCESS && *buffer) { LoadStringW(globals.hMainInst, IDS_TL_VER, wszVer, sizeof(wszVer)/sizeof(wszVer[0])); wsprintfW(&buffer[lstrlenW(buffer)], wszFormat, wszVer, valName); U(tvis).item.pszText = buffer; lenBuffer = MAX_LOAD_STRING; RegOpenKeyW(hInfoKey, wszGetPath, &hPath); RegQueryValueW(hPath, NULL, wszPath, &lenBuffer); RegCloseKey(hPath); } else U(tvis).item.pszText = valName; RegCloseKey(hInfoKey); wsprintfW(wszVer, wszFormat2, valParent, valName); U(tvis).item.lParam = CreateITEM_INFO(REGPATH, wszVer, valParent, wszPath); SendMessageW(globals.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis); } RegCloseKey(hCurKey); } RegCloseKey(hKey); SendMessageW(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hTL); }
static VOID DisplayStatus(VOID) { LONG Ret; HKEY HandleKey; DWORD Index, MaxLen, Handled; TCHAR * SubKey; BOOL Header; if (!OpenImageFileExecOptions(KEY_READ, NULL, &HandleKey)) { return; } Ret = RegQueryInfoKeyW(HandleKey, NULL, NULL, NULL, NULL, &MaxLen, NULL, NULL, NULL, NULL, NULL, NULL); if (Ret != ERROR_SUCCESS) { wprintf(L"DS: RegQueryInfoKey failed (%d)\n", Ret); RegCloseKey(HandleKey); return; } ++MaxLen; // NULL-char SubKey = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MaxLen * sizeof(WCHAR)); if (SubKey == NULL) { wprintf(L"DS: HeapAlloc failed\n"); RegCloseKey(HandleKey); return; } Index = 0; Handled = 0; Header = FALSE; do { Ret = RegEnumKeyW(HandleKey, Index, SubKey, MaxLen); if (Ret != ERROR_NO_MORE_ITEMS) { if (Image == NULL || wcscmp(SubKey, Image) == 0) { if (DisplayImageInfo(HandleKey, SubKey, &Header)) { ++Handled; } } ++Index; } } while (Ret != ERROR_NO_MORE_ITEMS); if (Handled == 0) { if (Image == NULL) { wprintf(L"No application has page heap enabled.\n"); } else { wprintf(L"Page heap is not enabled for %s\n", Image); } } HeapFree(GetProcessHeap(), 0, SubKey); RegCloseKey(HandleKey); }
static BOOL ViewTree_LoadTree(HKEY hKey, LPCWSTR pszKeyName, DWORD dwParentID) { DWORD dwIndex; WCHAR szKeyName[64], szText[MAX_PATH], *pch; DWORD Size, Value; PVIEWTREE_ENTRY pAllocated; // resize s_ViewTreeEntries Size = (s_ViewTreeEntryCount + 1) * sizeof(VIEWTREE_ENTRY); pAllocated = (PVIEWTREE_ENTRY)realloc(s_ViewTreeEntries, Size); if (pAllocated == NULL) return FALSE; // failure else s_ViewTreeEntries = pAllocated; PVIEWTREE_ENTRY pEntry = &s_ViewTreeEntries[s_ViewTreeEntryCount]; // dwID, dwParentID, szKeyName pEntry->dwID = s_ViewTreeEntryCount; pEntry->dwParentID = dwParentID; lstrcpynW(pEntry->szKeyName, pszKeyName, _countof(pEntry->szKeyName)); // Text, ResourceID pEntry->szText[0] = 0; pEntry->dwResourceID = 0; szText[0] = 0; Size = sizeof(szText); RegQueryValueExW(hKey, L"Text", NULL, NULL, LPBYTE(szText), &Size); if (szText[0] == L'@') { pch = wcsrchr(szText, L','); if (pch) { *pch = 0; dwIndex = abs(_wtoi(pch + 1)); pEntry->dwResourceID = dwIndex; } HINSTANCE hInst = LoadLibraryW(&szText[1]); LoadStringW(hInst, dwIndex, szText, _countof(szText)); FreeLibrary(hInst); } else { pEntry->dwResourceID = DWORD(-1); } lstrcpynW(pEntry->szText, szText, _countof(pEntry->szText)); // Type szText[0] = 0; RegQueryValueExW(hKey, L"Type", NULL, NULL, LPBYTE(szText), &Size); if (lstrcmpiW(szText, L"checkbox") == 0) pEntry->dwType = AETYPE_CHECKBOX; else if (lstrcmpiW(szText, L"radio") == 0) pEntry->dwType = AETYPE_RADIO; else if (lstrcmpiW(szText, L"group") == 0) pEntry->dwType = AETYPE_GROUP; else return FALSE; // failure pEntry->nIconID = -1; if (pEntry->dwType == AETYPE_GROUP) { // Bitmap (Icon) UINT nIconIndex = 0; Size = sizeof(szText); szText[0] = 0; RegQueryValueExW(hKey, L"Bitmap", NULL, NULL, LPBYTE(szText), &Size); WCHAR szExpanded[MAX_PATH]; ExpandEnvironmentStringsW(szText, szExpanded, _countof(szExpanded)); pch = wcsrchr(szExpanded, L','); if (pch) { *pch = 0; nIconIndex = abs(_wtoi(pch + 1)); } pEntry->nIconID = ViewTree_AddIcon(szExpanded, nIconIndex); } if (pEntry->dwType == AETYPE_GROUP) { pEntry->hkeyRoot = NULL; pEntry->szRegPath[0] = 0; pEntry->szValueName[0] = 0; pEntry->dwCheckedValue = 0; pEntry->bHasUncheckedValue = FALSE; pEntry->dwUncheckedValue = 0; pEntry->dwDefaultValue = 0; pEntry->hItem = NULL; pEntry->bGrayed = FALSE; pEntry->bChecked = FALSE; } else { // HKeyRoot HKEY HKeyRoot = HKEY_CURRENT_USER; Size = sizeof(HKeyRoot); RegQueryValueExW(hKey, L"HKeyRoot", NULL, NULL, LPBYTE(&HKeyRoot), &Size); pEntry->hkeyRoot = HKeyRoot; // RegPath pEntry->szRegPath[0] = 0; Size = sizeof(szText); RegQueryValueExW(hKey, L"RegPath", NULL, NULL, LPBYTE(szText), &Size); lstrcpynW(pEntry->szRegPath, szText, _countof(pEntry->szRegPath)); // ValueName pEntry->szValueName[0] = 0; Size = sizeof(szText); RegQueryValueExW(hKey, L"ValueName", NULL, NULL, LPBYTE(szText), &Size); lstrcpynW(pEntry->szValueName, szText, _countof(pEntry->szValueName)); // CheckedValue Size = sizeof(Value); Value = 0x00000001; RegQueryValueExW(hKey, L"CheckedValue", NULL, NULL, LPBYTE(&Value), &Size); pEntry->dwCheckedValue = Value; // UncheckedValue Size = sizeof(Value); Value = 0x00000000; pEntry->bHasUncheckedValue = TRUE; if (RegQueryValueExW(hKey, L"UncheckedValue", NULL, NULL, LPBYTE(&Value), &Size) != ERROR_SUCCESS) { pEntry->bHasUncheckedValue = FALSE; } pEntry->dwUncheckedValue = Value; // DefaultValue Size = sizeof(Value); Value = 0x00000001; RegQueryValueExW(hKey, L"DefaultValue", NULL, NULL, LPBYTE(&Value), &Size); pEntry->dwDefaultValue = Value; // hItem pEntry->hItem = NULL; // bGrayed, bChecked HKEY hkeyTarget; Value = pEntry->dwDefaultValue; pEntry->bGrayed = TRUE; if (RegOpenKeyExW(HKEY(pEntry->hkeyRoot), pEntry->szRegPath, 0, KEY_READ, &hkeyTarget) == ERROR_SUCCESS) { Size = sizeof(Value); if (RegQueryValueExW(hkeyTarget, pEntry->szValueName, NULL, NULL, LPBYTE(&Value), &Size) == ERROR_SUCCESS) { pEntry->bGrayed = FALSE; } RegCloseKey(hkeyTarget); } pEntry->bChecked = (Value == pEntry->dwCheckedValue); } // Grayed (ReactOS extension) Size = sizeof(Value); Value = FALSE; RegQueryValueExW(hKey, L"Grayed", NULL, NULL, LPBYTE(&Value), &Size); if (!pEntry->bGrayed) pEntry->bGrayed = Value; BOOL bIsGroup = (pEntry->dwType == AETYPE_GROUP); dwParentID = pEntry->dwID; ++s_ViewTreeEntryCount; if (!bIsGroup) return TRUE; // success // load the children dwIndex = 0; while (RegEnumKeyW(hKey, dwIndex, szKeyName, _countof(szKeyName)) == ERROR_SUCCESS) { HKEY hkeyChild; if (RegOpenKeyExW(hKey, szKeyName, 0, KEY_READ, &hkeyChild) != ERROR_SUCCESS) { ++dwIndex; continue; // failure } ViewTree_LoadTree(hkeyChild, szKeyName, dwParentID); RegCloseKey(hkeyChild); ++dwIndex; } return TRUE; // success }
static DWORD scmdatabase_load_services(struct scmdatabase *db) { DWORD err; int i; for (i = 0; TRUE; i++) { WCHAR szName[MAX_SERVICE_NAME]; struct service_entry *entry; HKEY hServiceKey; err = RegEnumKeyW(db->root_key, i, szName, MAX_SERVICE_NAME); if (err == ERROR_NO_MORE_ITEMS) break; if (err != 0) { WINE_ERR("Error %d reading key %d name - skipping\n", err, i); continue; } err = service_create(szName, &entry); if (err != ERROR_SUCCESS) break; WINE_TRACE("Loading service %s\n", wine_dbgstr_w(szName)); err = RegOpenKeyExW(db->root_key, szName, 0, KEY_READ, &hServiceKey); if (err == ERROR_SUCCESS) { err = load_service_config(hServiceKey, entry); RegCloseKey(hServiceKey); } if (err != ERROR_SUCCESS) { WINE_ERR("Error %d reading registry key for service %s - skipping\n", err, wine_dbgstr_w(szName)); free_service_entry(entry); continue; } if (entry->config.dwServiceType == 0) { /* Maybe an application only wrote some configuration in the service key. Continue silently */ WINE_TRACE("Even the service type not set for service %s - skipping\n", wine_dbgstr_w(szName)); free_service_entry(entry); continue; } if (!validate_service_config(entry)) { WINE_ERR("Invalid configuration of service %s - skipping\n", wine_dbgstr_w(szName)); free_service_entry(entry); continue; } entry->status.dwServiceType = entry->config.dwServiceType; entry->db = db; list_add_tail(&db->services, &entry->entry); } return ERROR_SUCCESS; }
static void AddCOMandAll(void) { TVINSERTSTRUCTW tvis; TVITEMW tvi; HTREEITEM curSearch; HKEY hKey, hCurKey, hInfo; WCHAR valName[MAX_LOAD_STRING]; WCHAR buffer[MAX_LOAD_STRING]; WCHAR wszComp[MAX_LOAD_STRING]; LONG lenBuffer; int i=-1; memset(&tvi, 0, sizeof(TVITEMW)); U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_CHILDREN; U(tvis).item.cchTextMax = MAX_LOAD_STRING; U(tvis).item.cChildren = 1; tvis.hInsertAfter = TVI_FIRST; if(RegOpenKeyW(HKEY_CLASSES_ROOT, wszCLSID, &hKey) != ERROR_SUCCESS) return; while(TRUE) { i++; if(RegEnumKeyW(hKey, i, valName, sizeof(valName)/sizeof(valName[0])) != ERROR_SUCCESS) break; if(RegOpenKeyW(hKey, valName, &hCurKey) != ERROR_SUCCESS) continue; lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]); tvis.hParent = tree.hAO; if(RegOpenKeyW(hCurKey, wszInProcServer32, &hInfo) == ERROR_SUCCESS) { if(RegQueryValueW(hInfo, NULL, buffer, &lenBuffer) == ERROR_SUCCESS && *buffer) if(!memcmp(buffer, wszOle32dll, sizeof(WCHAR[9])) ||!memcmp(buffer, wszOleAut32dll, sizeof(WCHAR[12]))) tvis.hParent = tree.hCLO; RegCloseKey(hInfo); } lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]); if(RegQueryValueW(hCurKey, NULL, buffer, &lenBuffer) == ERROR_SUCCESS && *buffer) U(tvis).item.pszText = buffer; else U(tvis).item.pszText = valName; U(tvis).item.lParam = CreateITEM_INFO(REGPATH|SHOWALL, valName, valName, NULL); if(tvis.hParent) SendMessageW(globals.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis); if(RegOpenKeyW(hCurKey, wszImplementedCategories, &hInfo) == ERROR_SUCCESS) { if(RegEnumKeyW(hInfo, 0, wszComp, sizeof(wszComp)/sizeof(wszComp[0])) != ERROR_SUCCESS) break; RegCloseKey(hInfo); if(tree.hGBCC) curSearch = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)tree.hGBCC); else curSearch = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)TVI_ROOT); while(curSearch) { tvi.hItem = curSearch; if(!SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi)) break; if(tvi.lParam && !lstrcmpW(((ITEM_INFO *)tvi.lParam)->info, wszComp)) { tvis.hParent = curSearch; memmove(&valName[6], valName, sizeof(WCHAR[MAX_LOAD_STRING-6])); memmove(valName, wszCLSID, sizeof(WCHAR[6])); U(tvis).item.lParam = CreateITEM_INFO(REGTOP|REGPATH|SHOWALL, valName, &valName[6], NULL); SendMessageW(globals.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis); break; } curSearch = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)curSearch); } } RegCloseKey(hCurKey); } RegCloseKey(hKey); SendMessageW(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hCLO); SendMessageW(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hAO); }