Skip to content

Instantly share code, notes, and snippets.

@smourier
Created August 24, 2024 12:40
Show Gist options
  • Save smourier/aa8b47aeb27e2bbe84fc6a2a423167bf to your computer and use it in GitHub Desktop.
Save smourier/aa8b47aeb27e2bbe84fc6a2a423167bf to your computer and use it in GitHub Desktop.
Update some (here photos) app's registry from outside the app itself.
#include <windows.h>
#include <userenv.h>
#include <atlbase.h>
#include <stdio.h>
#include <shlobj.h>
#include <string>
#pragma comment(lib, "userenv")
int main()
{
PWSTR localAppDataPath;
auto hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &localAppDataPath);
if (SUCCEEDED(hr))
{
std::wstring settingsPath = localAppDataPath;
CoTaskMemFree(localAppDataPath);
settingsPath += L"\\Packages\\Microsoft.Windows.Photos_8wekyb3d8bbwe\\Settings\\settings.dat";
wprintf(L"path:%s\n", settingsPath.c_str());
HKEY key;
auto err = RegLoadAppKey(settingsPath.c_str(), &key, KEY_ALL_ACCESS, 0, 0);
if (err == ERROR_SUCCESS)
{
DWORD index = 0;
do
{
wchar_t name[256];
if (RegEnumKey(key, index, name, 256) != ERROR_SUCCESS)
break;
wprintf(L"key:%s\n", name);
index++;
} while (true);
HKEY state;
if (RegOpenKey(key, L"LocalState", &state) == ERROR_SUCCESS)
{
DWORD index = 0;
do
{
wchar_t name[256];
DWORD size = 256;
DWORD type = 0;
if (RegEnumValue(state, index, name, &size, nullptr, &type, nullptr, nullptr) != ERROR_SUCCESS)
break;
wprintf(L"value:%s type:0x%08X\n", name, type);
index++;
} while (true);
const DWORD REG_APPX_SETTINGS_BOOL = 0x5F5E10C; // this is the special registry type for boolean
wchar_t boolText[] = L"true";
DWORD size = sizeof(boolText) + sizeof(FILETIME); // AppX settings.dat values are values + timestamp
auto bytes = new BYTE[size];
CopyMemory(bytes, boolText, sizeof(boolText)); // includes terminating zero
GetSystemTimeAsFileTime((LPFILETIME)(bytes + sizeof(boolText)));
err = RegSetValueEx(state, L"HeicCodecMissingTeachingTipStatus", 0, REG_APPX_SETTINGS_BOOL, bytes, size);
RegCloseKey(state);
}
RegCloseKey(key);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment