Fik dette fra bertel...
Mange tak
#include <windows.h>
#include <iostream>
int main(void)
{
HKEY hKey;
// First write
char SomeString[] = "Some String";
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Pop", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, 0) == ERROR_SUCCESS)
{
RegSetValueEx(hKey, "NetS", 0, REG_SZ, (BYTE *)SomeString, strlen(SomeString) + 1);
std::cout << "Did write value" << std::endl;
}
else
{
std::cout << "Failed to write value" << std::endl;
}
RegCloseKey(hKey);
// Then read
if(RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Pop", &hKey) == ERROR_SUCCESS)
{
char Buffer[1024] = "";
DWORD Size = sizeof(Buffer);
DWORD Type = REG_SZ;
RegQueryValueEx(hKey, "NetS", 0, &Type, (BYTE *)Buffer, &Size);
std::cout << "Read: " << Buffer << std::endl;
}
else
{
std::cout << "Failed to read value" << std::endl;
}
RegCloseKey(hKey);
return 0;
}