C++ update registry keys
i need from my program to change some registry values. not create new, only update. i've read something about TRegistry but its working only in C++ Builder, and i have Code::Blocks IDE with Digital Mars compiller. so i need some good function that will do this. google returned only threads about TRegistry, but i cant use this. if anyone knows, please help me.
btw… my 200th post ;)
ok, i solved it, for i have this source for example
// Registry.cpp : main project file.
#include "stdafx.h"
using namespace System;
using namespace System::Diagnostics;
using namespace Microsoft::Win32;
void WriteRegistry(RegistryKey __gc* ParentKey , String __gc* SubKey , String __gc* ValueName , Object *Value )
{
RegistryKey __gc* Key;
try
{
//Open the registry key.
Key = ParentKey->OpenSubKey(SubKey,true);
if (!Key) //if the key does not exist.
{
//Create the Subkey
Key = ParentKey->CreateSubKey(SubKey);
}
//Set the value.
Key->SetValue(ValueName, Value);
Console::WriteLine(S"Value:{0} for {1} is successfully written.", Value, ValueName);
}
catch (Exception *e)
{
Console::WriteLine(S"Error occurs in WriteRegistry", e->Message);
}
}
void ReadRegistry( RegistryKey __gc* ParentKey , String __gc* SubKey, String __gc* ValueName , Object *Value)
{
RegistryKey __gc* Key;
try
{
//Open the registry key.
Key = ParentKey->OpenSubKey(SubKey, true);
if (!Key) //if the key does not exist
{
throw new Exception(S"The registry key does not exist");
}
//Get the value.
Value = Key->GetValue(ValueName);
Console::Write(S"Value:{0} for {1} is successfully retrieved.", Value, ValueName);
}
catch( Exception *e)
{
Console::Write(S"Error occurs in ReadRegistry", e->Message );
}
}
int main()
{
Int32 i = 123;
System::Object* obj = __box(i);
Console::Write(S"\tWelcome....\n");
Console::Write(S"\tblahblahblah\n");
WriteRegistry(Registry::CurrentUser, S"Software\\test", S"Count", obj);
Object * Value;
ReadRegistry(Registry::CurrentUser, S"Software\\test", S"Count", Value);
Console::ReadLine();
}
compiled with c++ visual studio 2005 express… but if you look carefully at the source, you see that i have the int32, declared for now as 123, which will in registry appear as REG_DWORD. but i need to change it to REG_BINARY, because i need to enter some data like: ""DigitalProductId"=hex:a4,00,00,00,03,00……." so its in hex and i cant use REG_DWORD and Int32 for this. so if someone can help me with this, thanks.