#include <iostream> #include <string> #include <sstream> #include <fstream> #include <Windows.h> using namespace std; int main() { HKEY key; if (RegOpenKey(HKEY_CURRENT_USER, TEXT("Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"), &key) != ERROR_SUCCESS) { cout << "unable to open registry"; } DWORD value_data = 0; if (RegSetValueEx(key, TEXT("SystemUsesLightTheme"), 0, REG_DWORD, (const BYTE*)&value_data, sizeof(value_data)) != ERROR_SUCCESS) { RegCloseKey(key); cout << "Unable to set registry value value_name"; } else { cout << "value_name was set" << endl; } }
另外,RegCreateKeyEx是用来创建注册表里的键
RegCreateKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\Con", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL)