Saturday, March 04, 2006

C++: Edit The Registry in Borland C++ Builder 5


#include <registry.hpp>//put this line in your header file

void MakeSerKey(String gSerial)
{
TRegistry *Reg = new TRegistry();

Reg->RootKey = HKEY_LOCAL_MACHINE;
if(!Reg->KeyExists("SOFTWARE\\TestSoftware"))
{
if(!Reg->CreateKey("Software\\TestSoftware"))
{
ShowMessage("Can't Create Key","Error",MB_OK);
delete Reg;
return;
}

try
{
if(Reg->OpenKey("Software\\TestSoftware",FALSE))
{
Reg->WriteString("SERIAL",gSerial);
Reg->CloseKey();
}
else
{
ShowMessage("Registry RootDir error");
}
Reg->CloseKey();
}
catch(ERegistryException &E)
{
ShowMessage(E.Message);
delete Reg;
return;
}
}
delete Reg;
}

void UpdateSerKey(String gSerial)
{
TRegistry *Reg = new TRegistry();

Reg->RootKey = HKEY_LOCAL_MACHINE;
if(Reg->KeyExists("SOFTWARE\\TestSoftware"))
{
try
{
if(Reg->OpenKey("Software\\TestSoftware",FALSE))
{
Reg->WriteString("SERIAL",gSerial);
Reg->CloseKey();
}
else
{
ShowMessage("Can't open key.");
}
Reg->CloseKey();
}
catch(ERegistryException &E)
{
ShowMessage(E.Message);
delete Reg;
return;
}
}
delete Reg;
}

No comments: